Hello! I use this function:

StretchDIBits(deviceContext, 0, 0, buffer->Width, buffer->Height, 0, 0, buffer->Width, buffer->Height, buffer->Memory, &buffer->Info, DIB_RGB_COLORS, SRCCOPY); 

But it is slow compared to BitBlt. The question is how to replace it?

    1 answer 1

    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)?

    • BitBlt draws in my cycle, it is necessary to constantly create Bitmap and HDC or you can create it once and all - helldrg
    • And ReleaseDC (bmDC); is there another HWND to add in the parameter? - helldrg
    • And Bitmap and HDC can be created once at the beginning of the program, then in a cycle, draw through BitBtl and at the end, when the program is completed, delete everything? Or so in a cycle and write everything? - helldrg
    • And do the image immediately BitBlt - this is how? - helldrg
    • What do you think is better to display pictures via BitBlt or StretchDIBits?) - helldrg