All pastes #947977 Raw Edit

Unbenannt

public text v1 · immutable
·published 2008-03-18 20:53 UTC
rendered paste body
HBITMAP CreateBitmapFromPixel(HDC hDC, UINT uWidth, UINT uHeight, UINT uBitsPerPixel, LPVOID pBits) {
	HBITMAP hBitmap = 0;
	if (!uWidth || !uHeight || !uBitsPerPixel) return hBitmap;
	
	LONG lBmpSize = uWidth * uHeight * (uBitsPerPixel/8);
	
	BITMAPINFO bmpInfo = { 0 };
	bmpInfo.bmiHeader.biBitCount = uBitsPerPixel;
	bmpInfo.bmiHeader.biHeight = uHeight;
	bmpInfo.bmiHeader.biWidth = uWidth;
	bmpInfo.bmiHeader.biPlanes = 1;
	bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	// Pointer to access the pixels of bitmap
	UINT* pPixels = 0;
	hBitmap = CreateDIBSection(hDC, (BITMAPINFO *)&
                               bmpInfo, DIB_RGB_COLORS, (void **)&
                               pPixels, NULL, 0);
	
	if (!hBitmap) {
		return hBitmap; // return if invalid bitmaps
	}
	
	//SetBitmapBits(hBitmap, lBmpSize, pBits);
	memmove(pPixels, pBits, lBmpSize);
	return hBitmap;
}