기본카테고리

[C++]GDI+ 배경을 투명하게 처리하는 방법

DevAdd 2012. 1. 4. 16:05




// File에서 Bitmap을 Loading 한다
BOOL LoadBitmap(Bitmap **ppBitmap, LPCTSTR lpszBitmap)
{
CFileFind ff;
if(!ff.FindFile(lpszBitmap))
return FALSE;

WCHAR wFile[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, lpszBitmap, -1, wFile, MAX_PATH );

*ppBitmap = Bitmap::FromFile(wFile, TRUE);
if(*ppBitmap == NULL)
return FALSE;

return TRUE;
}

 

...

 

Bitmap* pBitmap = NULL;

LoadBitmap(&pBitmap, _T("C:\\연습.png"));

 

ColorMatrix colorMatrix =
{
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, m_rTransparency, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};

ImageAttributes ia;
ia.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);

Graphics graphics(lpDrawItemStruct->hDC);
graphics.DrawImage(pBitmap, Rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()), 0, 0, pBitmap->GetWidth(), pBitmap->GetHeight(), UnitPixel, &ia);