利用CImage顯示透明PNG圖片
類CImage,標頭檔案atlimage.h
1.顯示背景透明的PNG圖片
CImage m_Image;
m_Image.Load(圖片路徑);//裝載圖片
for(int i = 0; i < m_Image.GetWidth(); i++)
{
for(int j = 0; j < m_Image.GetHeight(); j++)
{
unsigned char* pucColor = reinterpret_cast<unsigned char *>(m_Image.GetPixelAddress(i , j));
pucColor[0] = pucColor[0] * pucColor[3] / 255;
pucColor[1] = pucColor[1] * pucColor[3] / 255;
pucColor[2] = pucColor[2] * pucColor[3] / 255;
}
}
m_Image.Draw(...)顯示圖片
BOOL CImage::Draw( HDC hDestDC, int xDest, int yDest, int nDestWidth,
int nDestHeight, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight )
2.顯示整體半透明PNG圖片
BOOL CImage::AlphaBlend( HDC hDestDC, int xDest, int yDest,
int nDestWidth, int nDestHeight, int xSrc, int ySrc, int nSrcWidth,
int nSrcHeight, BYTE bSrcAlpha, BYTE bBlendOp )
bSrcAlpha=255表示圖片整體不透明
bSrcAlpha=0表示整體透明