int memDib = createDIB(Math.max(srcWidth, destWidth), Math.max(srcHeight, destHeight), 32);
int memDib = createDIB(Math.max(srcWidth, destWidth), Math.max(srcHeight, destHeight));
void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, BITMAP bm, int imgWidth, int imgHeight) {	/* Simple cases */	if (srcImage.alpha == 0) return;	if (srcImage.alpha == 255) {		drawBitmap(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);		return;	}	/* Check clipping */	Rectangle rect = getClipping();	rect = rect.intersection(new Rectangle(destX, destY, destWidth, destHeight));	if (rect.isEmpty()) return;	/* 	* Optimization.  Recalculate src and dest rectangles so that	* only the clipping area is drawn.	*/	rect.width = Math.max(rect.width, Compatibility.ceil(destWidth, srcWidth));	rect.height = Math.max(rect.height, Compatibility.ceil(destHeight, srcHeight));	int sx1 = srcX + (((rect.x - destX) * srcWidth) / destWidth);	int sx2 = srcX + ((((rect.x + rect.width) - destX) * srcWidth) / destWidth);	int sy1 = srcY + (((rect.y - destY) * srcHeight) / destHeight);	int sy2 = srcY + ((((rect.y + rect.height) - destY) * srcHeight) / destHeight);	destX = rect.x;	destY = rect.y;	destWidth = rect.width;	destHeight = rect.height;	srcX = sx1;	srcY = sy1;	srcWidth = sx2 - sx1;	srcHeight = sy2 - sy1;		/* Create resources */	int srcHdc = OS.CreateCompatibleDC(handle);	int oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle);	int memHdc = OS.CreateCompatibleDC(handle);	int memDib = createDIB(Math.max(srcWidth, destWidth), Math.max(srcHeight, destHeight), 32);	int oldMemBitmap = OS.SelectObject(memHdc, memDib);	BITMAP dibBM = new BITMAP();	OS.GetObject(memDib, BITMAP.sizeof, dibBM);	int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;	/* Get the background pixels */	OS.BitBlt(memHdc, 0, 0, destWidth, destHeight, handle, destX, destY, OS.SRCCOPY);	byte[] destData = new byte[sizeInBytes];	OS.MoveMemory(destData, dibBM.bmBits, sizeInBytes); 	/* Get the foreground pixels */ 	OS.BitBlt(memHdc, 0, 0, srcWidth, srcHeight, srcHdc, srcX, srcY, OS.SRCCOPY); 	byte[] srcData = new byte[sizeInBytes];	OS.MoveMemory(srcData, dibBM.bmBits, sizeInBytes);		/* Merge the alpha channel in place */	int alpha = srcImage.alpha;	final boolean hasAlphaChannel = (srcImage.alpha == -1);	if (hasAlphaChannel) {		final int apinc = imgWidth - srcWidth;		final int spinc = dibBM.bmWidthBytes - srcWidth * 4;		int ap = srcY * imgWidth + srcX, sp = 3;		byte[] alphaData = srcImage.alphaData;		for (int y = 0; y < srcHeight; ++y) {			for (int x = 0; x < srcWidth; ++x) {				srcData[sp] = alphaData[ap++];				sp += 4;			}			ap += apinc;			sp += spinc;		}	}		/* Scale the foreground pixels with alpha */	if (!OS.IsWinCE) OS.SetStretchBltMode(memHdc, OS.COLORONCOLOR);	OS.MoveMemory(dibBM.bmBits, srcData, sizeInBytes);	OS.StretchBlt(memHdc, 0, 0, destWidth, destHeight, memHdc, 0, 0, srcWidth, srcHeight, OS.SRCCOPY);	OS.MoveMemory(srcData, dibBM.bmBits, sizeInBytes);		/* Compose the pixels */	final int dpinc = dibBM.bmWidthBytes - destWidth * 4;	int dp = 0;	for (int y = 0; y < destHeight; ++y) {		for (int x = 0; x < destWidth; ++x) {			if (hasAlphaChannel) alpha = srcData[dp + 3] & 0xff;			destData[dp] += ((srcData[dp] & 0xff) - (destData[dp] & 0xff)) * alpha / 255;			destData[dp + 1] += ((srcData[dp + 1] & 0xff) - (destData[dp + 1] & 0xff)) * alpha / 255;			destData[dp + 2] += ((srcData[dp + 2] & 0xff) - (destData[dp + 2] & 0xff)) * alpha / 255;			dp += 4;		}		dp += dpinc;	}	/* Draw the composed pixels */	OS.MoveMemory(dibBM.bmBits, destData, sizeInBytes);	OS.BitBlt(handle, destX, destY, destWidth, destHeight, memHdc, 0, 0, OS.SRCCOPY);	/* Free resources */	OS.SelectObject(memHdc, oldMemBitmap);	OS.DeleteDC(memHdc);	OS.DeleteObject(memDib);	OS.SelectObject(srcHdc, oldSrcBitmap);	OS.DeleteDC(srcHdc);}