(GDI)----------------------------------------------------
CPaintDC dc(this);
CBitmap FootballBMP;
FootballBMP.LoadBitmap(IDB_FOOTBALLBMP);
CDC ImageDC;
ImageDC.CreateCompatibleDC(&dc);
CBitmap *pOldImageBMP = ImageDC.SelectObject(&FootballBMP);
TransparentBlt(dc.m_hDC, 0, 0, 218, 199, ImageDC.m_hDC, 0, 0, 218, 199, RGB(0xff,0xff,0xff));
ImageDC.SelectObject(pOldImageBMP);
(GDI+ )----------------------------------------------------
void CTestGdiDlg::DrawPNG()
{
CDC *pDC = GetDC();
Graphics graph(pDC->m_hDC);
ImageAttributes imAtt;
int n1 = 20;
int n2 = 255;//最重要的就是调整这两数
imAtt.SetColorKey(Color(n1,n1,n1),Color(n2,n2,n2),ColorAdjustTypeDefault);
graph.SetSmoothingMode(SmoothingModeAntiAlias);
Image imageBlue(L"a.png");
graph.DrawImage(&imageBlue,Rect(0,0,300,300),0,0,200,200,UnitPixel,&imAtt);
}
(GetEncoderClsid)--------------------------------------------------------
INT CTestGdiDlg::GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return -1; // Failure
}