How to convert an Array of pixels to HBITMAP

后端 未结 3 1652
天涯浪人
天涯浪人 2020-12-17 20:46

I have an array of pixels which I need to convert to HBITMAP in order to display it in a window. I tried to use CreateDIBitmap() but I don\'t have the BMP headers. I tried

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 21:03

    The other answers here are very helpful, but i ended up being able to achieve it with just 1 line.

    HBITMAP hBm = CreateBitmap(width,height,1,32,pixels); // 1 plane, 32 bits
    

    Hope it may be useful to any future readers.


    Also, there's CreateCompatibleBitmap and SetDIBits incase you need to use a device context.

    At MSDN for CreateDIBitmap it states:

    Calling CreateDIBitmap with fdwInit as CBM_INIT is equivalent to calling the CreateCompatibleBitmap function to create a DDB in the format of the device and then calling the SetDIBits function to translate the DIB bits to the DDB.

提交回复
热议问题