Ja, das geht. Ist ja auch schon wieder über ein Jahr her
Soweit ich das in Erinnerung habe legst du dir eine Variable vom
Typ HBitmap an.
HBitmap hBmp = CreateDDBFromPixel(hDC, width, height, bpp, NULL);
Mit NULL am Ende, reservierst du quasi den Speicher schonmal.
HBITMAP CreateDDBFromPixel( HDC hDC, UINT uWidth, UINT uHeight, UINT uBitsPerPixel, LPVOID pBits )
{
HBITMAP HBitmap = NULL;
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.biSizeImage = uWidth * uHeight * (uBitsPerPixel / 8);
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biCompression = BI_RGB;
// Pointer to access the pixels of bitmap
UINT * pPixels = NULL;
HBitmap = CreateDIBitmap(hDC,(BITMAPINFOHEADER*)&bmpInfo.bmiHeader,CBM_INIT,
pBits,(BITMAPINFO*)&bmpInfo,DIB_RGB_COLORS);
if (!HBitmap)
{
return HBitmap;//hBitmap; // return if invalid bitmaps
}
return HBitmap;
}
Um dann das Bild in zu zeichen, sollte das glaueb ich so ablaufen...
OnPaint - Methode
{
CPaintDC dc(this);
dc.SetStretchBltMode(COLORONCOLOR);
unsigned char* pBuffer = DEIN_BUFFER
// set bitmap bits into bitmap
::SetDIBits(NULL,hBmp,0,480,pBuffer,&Bitmapinfo,DIB_RGB_COLORS);
CBitmap* pBitmap = CBitmap::FromHandle(hBmp);
CDC cdc;
cdc.CreateCompatibleDC(&dc);
//CBitmap bitmap;
CBitmap* pOldBitmap = cdc.SelectObject(pBitmap); dc.BitBlt(rect.TopLeft().x,rect.TopLeft().y,rect.Width(),rect.Height(),&cdc,0,0,SRCCOPY);
cdc.SelectObject(pOldBitmap);
ReleaseDC(&cdc);
cdc.DeleteDC();
CDialog::OnPaint();
}
Ok, dann viel Spaß beim Probieren.
Grüße,
xiaoluo