Loading image from memory, GDI +

Here's a quick and easy question: using GDI + from C ++, how do I load an image from pixel data into memory?

+3
source share
5 answers

Probably not as easy as you hoped, but you can make a BMP file in memory with your pixel data:

If necessary, translate your data in BITMAP format. If you already have, say, 24-bit RGB pixel data, it is likely that translation is not required.

Create (in memory) a BITMAPFILEHEADER structure and then a BITMAPINFO structure.

, , IStream, GDI + . , ( ) :

  • GlobalAlloc() BITMAPFILEHEADER, BITMAPINFO .
  • BITMAPFILEHEADER, BITMAPINFO ( GlobalLock, ).
  • CreateStreamOnHGlobal(), IStream BMP .

GDI + Image:: FromStream(), GDI +.

!

+4

bitmap, BITMAPINFO , :

BITMAPINFO bmi;
memset(&bmi, 0, sizeof(bmi));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = 32;
bmi.bmiHeader.biHeight = 32;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biBitCount = 24;
char data[32 * 32 * 3];
// Write pixels to 'data' however you want...
Gdiplus::Bitmap* myImage = new Gdiplus::Bitmap(&bmi, data);

RGB, BITMAPINFO RGBQUADS .. ..

+3

SHCreateMemStream, .

IStream *pStream = SHCreateMemStream((BYTE *) InputBuffer, Size);
// Do what you want
pStream->Release();
+3

" " , , TIF, PNG ..? , System.Drawing.Image.FromStream.

0

, GDI + (rc). .

0

Source: https://habr.com/ru/post/1721527/


All Articles