admin管理员组

文章数量:1532135

2024年6月20日发(作者:)

vc++加载透明png图片方法

方法1:

+画透明图层(

alpha

)的png图片

stdafx加入如下:

#include //初始化一下com口

#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);

本文标签: 图片代码进行转换透明