Beispiel #1
0
HBITMAP LoadTransparentImage(wchar_t *fileName)
{
	if (m_pImageFactory != NULL && IsFileExists(fileName) == TRUE)
	{
		IImage*			pImage = NULL;
		IBitmapImage*	pBitmapImage = NULL;
		ImageInfo		imageInfo; 
		BitmapData		bitmapData;

		m_pImageFactory->CreateImageFromFile(fileName, &pImage);
		m_pImageFactory->CreateBitmapFromImage(pImage, 0, 0, 
						PixelFormat32bppPARGB, InterpolationHintNearestNeighbor, 
						&pBitmapImage);
		pImage->GetImageInfo(&imageInfo);  
		RECT rect = {0, 0, imageInfo.Width, imageInfo.Height}; 

		pBitmapImage->LockBits(&rect, ImageLockModeRead, 
								PixelFormat32bppPARGB, &bitmapData);

		return CreateBitmap( imageInfo.Width, imageInfo.Height, 1, 
			GetPixelFormatSize(imageInfo.PixelFormat), bitmapData.Scan0);
	}
	return NULL;
};
Beispiel #2
0
WMAlphaBitmap::WMAlphaBitmap(IImage* img) 
{
#if defined(_WIN32_WCE)	
	IImagingFactory *pImgFactory = NULL;

	mWidth = 0;
	mHeight = 0;
	mImgBuf = NULL;

	HRESULT co_init_result = CoInitializeEx(NULL, 0/*COINIT_APARTMENTTHREADED*/);
	if ( (co_init_result == S_OK) || (co_init_result == S_FALSE)  ) {
		msg_out("CoInitializeEx OK");
		if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory,
			NULL,
			CLSCTX_INPROC_SERVER,
			IID_IImagingFactory,
			(void **)&pImgFactory)))
		{
			ImageInfo imgInfo;
			img->GetImageInfo(&imgInfo);
			mWidth = imgInfo.Width;
			mHeight = imgInfo.Height;
			IBitmapImage* pBitmap = 0;

			if ( SUCCEEDED(pImgFactory->CreateBitmapFromImage(	img,
																mWidth,
																mHeight,
																PixelFormat32bppARGB,
																InterpolationHintDefault,
																&pBitmap) )) {
				msg_out("Create Bitmap OK");
				RECT rc = { 0, 0, mWidth, mHeight};
				BitmapData bitmap_data;
				if ( SUCCEEDED(pBitmap->LockBits(	&rc,
													ImageLockModeRead,
													PixelFormatDontCare,
													&bitmap_data))) {
					//
					msg_out("Lock Bits OK");
					void* src_buf = bitmap_data.Scan0;
					int stride = bitmap_data.Stride;
					int w = bitmap_data.Width;
					int h = bitmap_data.Height;
					mImgBuf = new unsigned int[w*h];
					if (mImgBuf != 0) {
						msg_out("Img buffer allocated OK");
						// start convert
						{
							unsigned int* dst = mImgBuf;
							unsigned int* src;
							int x;
							int y;
							for (y = 0 ; y < h; y++) {
								if (stride < 0) {
									src = (unsigned int*)(((unsigned char*)src_buf) + (h-1-y)*(-stride));
								}
								else {
									src = (unsigned int*)(((unsigned char*)src_buf) + y*(stride));
								}
								for (x = w; x > 0; x--) {
									*dst++ = *src++;
								}
							}
						}
						msg_out("Convert to img buffer finished OK");
						// finish convert
					}
					else {
						err_out("Image Buffer not allocated !");
					}
					pBitmap->UnlockBits(&bitmap_data);
				}
				else {
					err_out("Bitmap bits not locked !");
				}
				pBitmap->Release();
			}

            pImgFactory->Release();
		}
		CoUninitialize();
	}
	else {
		err_out("CoInitializeEx not initialized !");
	}
#endif //#if defined(_WIN32_WCE)
}