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.
Post Reply
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

How to create a DIB Bitmap from a Byte Array?

Post by Parduz »

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?



Thanks.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

Create an empty wxBitmap with the correct size and use raw bitmap access to write the RGB data into it:
https://docs.wxwidgets.org/trunk/classw ... _data.html

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