- 작성시간 : 2009/03/09 14:45
- 퍼머링크 : jjunda.egloos.com/4226089
- 덧글수 : 0
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'[출처] http://www.christec.co.nz/blog/archives/361
// 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);
}



최근 덧글