GoodDay and BadDay

jjunda.egloos.com

포토로그



[WinCE]Imaging API를 이용한 PNG, GIF, JPEG파일 표현 프로그래밍(Programming)

Drawing PNGs

Previous applications in this series have utilised Windows Bitmap (*.bmp) formatted images. This application is different since the application includes PNG formatted images to display on the sound effect buttons.

Prior to Windows Mobile 5.0 there was no general purpose API to manipulate images compressed in common image formats such as JPEGs, PNGs or GIFs (although there were options such as SHLoadImageFile). Windows Mobile 5.0 introduced a COM based Imaging API that offers a large number of image codecs as well as image manipulation functionality.

One benefit of using this API with PNG files is the ability for it to keep alpha transparency information in order to draw non rectangular images over top of existing content. The following subroutine can be used to draw a PNG onto an existing GDI device context.

// Draw an alpha blended image on the device context 'hdc'
// within the rectangle defined by 'prcBounds'.
static BOOL DrawAlphaImage(HDC hDC, RECT * prcBounds,
WCHAR * pszImageFileName)
{
// Create an instance of the ImagingFactory class
IImagingFactory *pFactory = NULL;
HRESULT hr = CoCreateInstance(CLSID_ImagingFactory, NULL,
CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void**)&pFactory);
if (hr == S_OK)
{
// Call the CreateImageFromFile method to load the image
// into memory.
IImage *pImage = NULL;
hr = pFactory->CreateImageFromFile(pszImageFileName, &pImage);
if (hr == S_OK)
{
// And finally draw the image onto the device context
hr = pImage->Draw(hDC, prcBounds, NULL);
 
// Free the COM objects
pImage->Release();
pImage = NULL;
}
 
pFactory->Release();
pFactory = NULL;
}
 
return (hr == S_OK);
}

[출처] http://www.christec.co.nz/blog/archives/361




메모장

곧 봄이다.. 나른나른..

W 위젯