Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win32 C/C++ Load Image from memory buffer

I want to load an image (.bmp) file on a Win32 application, but I do not want to use the standard LoadBitmap/LoadImage from Windows API: I want it to load from a buffer that is already in memory. I can easily load a bitmap directly from a file and print it on the screen, but this issue is making me stuck.

What I'm looking for is a function that works like this:

HBITMAP LoadBitmapFromBuffer(char* buffer, int width, int height);
like image 496
Bruno Avatar asked May 22 '10 03:05

Bruno


2 Answers

Try CreateBitmap():

HBITMAP LoadBitmapFromBuffer(char *buffer, int width, int height)
{
    return CreateBitmap(width, height, 1, 24, buffer);
}
like image 169
Adam Rosenfield Avatar answered Oct 24 '22 02:10

Adam Rosenfield


No, but you can create a new bitmap the size of the current one in memory, and write your memory structure onto it.

You're looking for the CreateBitmap function. Set lpvBits to your data.

like image 33
Billy ONeal Avatar answered Oct 24 '22 03:10

Billy ONeal