this is done the easiest way somewhere like this:
// Создаём bitmap контекст HBITMAP bm = CreateBitmap( buffer->Width, buffer->Height, 1/*planes*/, buffer->Info.bmiHeader.biBitCount, buffer->Memory); HDC bmDC = CreateCompatibleDC(0); SelectObject(bmDC,bm); // Теперь можно рендерить BitBlt(deviceContext, 0/*x*/,0/*y*/, buffer->Width, buffer->Height, bmDC, 0,0, SRCCOPY); // Что б не было утечки памяти, когда картинка не нужна - надо освободить память DeleteDC(bmDC); DeleteObject(bm);
To work with memory directly, you need the same section:
void ** bits = null; HDC bmDC = CreateCompatibleDC(0); HBITMAP bm = CreateDIBSection(bmDC,buffer->Info,DIB_RGB_COLORS,&bits,0,0); SelectObject(bmDC,bm);
Then you need to copy the data exactly to the memory area issued by the system and work with the bits. This link can be copied after copying to buffer-> Memory https://msdn.microsoft.com/ru-ru/library/windows/desktop/dd183494%28v=vs.85%29.aspx Releasing (DeleteObject, DeleteDC) and draw (bitblt) also by itself.
Draw win can only dc. But this dc must be associated with bitmap. Therefore, so.
Check that CreateBitmap returns non-zero. F-tion is quite "harmful." It does not support all formats. The format is specified in the penultimate parameter. I also came across the fact that the lines of the picture in some cases need to be aligned on the boundaries of a double word, otherwise the picture "warps" diagonally to one side.
If you need to load from memory or disk, you can do this: How to load a picture from memory C ++ (Win)?