admin管理员组文章数量:1532135
2024年6月20日发(作者:)
vc++加载透明png图片方法
方法1:
+画透明图层(
alpha
)的png图片
stdafx加入如下:
#include
#include "GdiPlus.h"
using namespace Gdiplus;
#pragma comment(lib,"")
开始初始化:
在app类的声明里(.h)加入:
ULONG_PTR m_gdiplusToken;
InitInstance()里加入://若没有usingnamespace Gdiplus; 就要在前面加Gdiplus::
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
重载ExitInstance,加入GdiplusShutdown(m_gdiplusToken);
int CxxxApp::ExitInstance()
{
}
// TODO: 在此添加专用代码和/或调用基类
GdiplusShutdown(m_gdiplusToken);
return CWinApp::ExitInstance();
显示图片的过程如下
CClientDC *pDC = new CClientDC(GetDlgItem(IDC_STATIC_PIC));
CRect rect;
GetDlgItem(IDC_STATIC_PIC)->GetWindowRect(&rect);
Graphics graphics(pDC->m_hDC); // Create a GDI+ graphics object
Image image(_T("")); // Construct an image
age(&image, 0, 0, th(),
ght());
delete pDC;
这是用GDI+来显示图片。
绘制带alpha透明图层的
png图片
用MFC自带的CImage也可以显示,不过要稍微进行转换才能得到正
常的带α通道的png图片!
在画图前进行一次转换,其中Image是CImage的对象
if (() == 32) //确认该图像包含Alpha通道
{
int i;
int j;
for (i = 0; i < th(); i++)
{
for (j = 0; j < ght(); j++)
{
}
byte *pByte = (byte
pByte[0] = pByte[0] * pByte[3] / 255;
pByte[1] = pByte[1] * pByte[3] / 255;
pByte[2] = pByte[2] * pByte[3] / 255;
*)elAddress(i, j);
版权声明:本文标题:vc++加载透明png图片方法 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1718817464a729006.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论