Tímto kódem už se to nějak rýsuje
HBITMAP LoadPngImage(HDC hdc, LPCTSTR filename)
{
IImagingFactory* pImageFactory = 0;
IImage* pImage = 0;
ImageInfo imageInfo;
CoInitializeEx(0, COINIT_MULTITHREADED);
HBITMAP hBitmap = 0;
LPBYTE lpByte;
if (SUCCEEDED(CoCreateInstance(CLSID_ImagingFactory, 0, CLSCTX_INPROC_SERVER,
IID_IImagingFactory, (void**)&pImageFactory)))
{
if (SUCCEEDED(pImageFactory->CreateImageFromFile(filename, &pImage))
&& SUCCEEDED(pImage->GetImageInfo(&imageInfo)))
{
BITMAPINFO *pbinfo ;
pbinfo = (BITMAPINFO *)calloc(1, sizeof(BITMAPINFO) + 4 * sizeof(INT)) ;
if(!pbinfo)
return FALSE ;
pbinfo->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
pbinfo->bmiHeader.biWidth = imageInfo.Width ;
pbinfo->bmiHeader.biHeight = -imageInfo.Height ;
pbinfo->bmiHeader.biPlanes = 1;
pbinfo->bmiHeader.biBitCount = 32;
pbinfo->bmiHeader.biCompression = BI_ALPHABITFIELDS;
pbinfo->bmiHeader.biSizeImage = 0 ;
pbinfo->bmiHeader.biXPelsPerMeter = 11811;
pbinfo->bmiHeader.biYPelsPerMeter = 11811;
pbinfo->bmiHeader.biClrUsed = 0;
pbinfo->bmiHeader.biClrImportant = 0;
int *pMask = (int*)&(pbinfo->bmiColors[0]) ;
*pMask++ = 0x00FF0000 ;
*pMask++ = 0x0000FF00 ;
*pMask++ = 0x000000FF ;
*pMask++ = 0xFF000000 ;
hBitmap = CreateDIBSection(NULL, pbinfo, DIB_RGB_COLORS,
(void **)&lpByte, NULL, 0) ;
free(pbinfo) ;
if(!hBitmap || !lpByte)
return FALSE ;
RECT rect = {0, 0, imageInfo.Width, imageInfo.Height};
IBitmapImage *pBitmapImage;
BitmapData bitmapData;
bitmapData.Width = imageInfo.Width;
bitmapData.Height = imageInfo.Height;
bitmapData.PixelFormat = imageInfo.PixelFormat;
pBitmapImage = NULL;
pImageFactory->CreateBitmapFromImage(pImage, imageInfo.Width,
imageInfo.Height, PIXFMT_32BPP_ARGB,
InterpolationHintDefault,
&pBitmapImage);
pBitmapImage->LockBits(&rect, ImageLockModeRead,
PIXFMT_32BPP_ARGB, &bitmapData);
memcpy(lpByte, bitmapData.Scan0, imageInfo.Width * imageInfo.Height * 4);
pBitmapImage->UnlockBits(&bitmapData);
pBitmapImage->Release();
pImage->Release();
}
pImageFactory->Release();
}
CoUninitialize();
for (UINT y=0; y<imageInfo.Height; y++)
{
BYTE * pPixel = (BYTE *) lpByte + imageInfo.Width * 4 * y;
for (UINT x=0; x<imageInfo.Width; x++)
{
pPixel[0] = pPixel[0] * pPixel[3] / 255;
pPixel[1] = pPixel[1] * pPixel[3] / 255;
pPixel[2] = pPixel[2] * pPixel[3] / 255;
pPixel += 4;
}
}
return hBitmap;
}
voláním z
....
HDC hdcMem = CreateCompatibleDC (g_hdcMem);
HBITMAP hIco = LoadPngImage(g_hdcMem,iconpath);
SelectObject (hdcMem, hIco);
BitBlt (g_hdcMem, 10, 10, 96, 96, hdcMem, 0, 0, SRCPAINT);
....
Průhledný PNG zobrazí skvěle, ale převede ho do asi 256barev, takže rozdíl je znatelný,
níže příklad jak to vypadá
Připojen obrázek.
Nevěděl by někdo jak to ještě poštelovat?
Možná bude problém s BitBlt. AlphaBlend, který by se asi hodil, WinCE nedodporuje.
Díky