How to create a DIB Bitmap from a Byte Array?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
User avatar
Knows some wx things
Knows some wx things
Posts: 32
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

How to create a DIB Bitmap from a Byte Array?

Postby Parduz » Thu Dec 06, 2018 2:54 pm

I have a byte array containing the "raw" data (i mean: the pixels) of a 4-bit-per-pixels grayscale image. I receive this data via RS232 from an old device and i can't change this. But I need to draw this image on a wxPanel.

I have an old code made with C++Builder 2006 which initialize a DIB bmp with a 16 color palette, and then it memcpy the array in it each time i receive a new image, convert to screen bpp while scaling it x3 and finally show it on the screen.

I need to do this with wxWidgets (and make it working in both Windows and Linux) but i'm struggling to find how to do the same.

How could i show that array of bytes as an image using wxWidgets 3.0.4?


User avatar
Posts: 12816
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to create a DIB Bitmap from a Byte Array?

Postby doublemax » Thu Dec 06, 2018 3:01 pm

Create an empty wxBitmap with the correct size and use raw bitmap access to write the RGB data into it: ... _data.html

(You have to convert it to 24bit RGB).
Use the source, Luke!

Return to “C++ Development”

Who is online

Users browsing this forum: No registered users and 17 guests