DRz
DRz

Reputation: 1156

Convert Mono8 image buffer to displayable format for wx.Bitmap in wxPython Phoenix in Python

I am new to image processing.
I currently have an image buffer encoded in Mono8.

I am trying to display it using a wx.Bitmap. However, I only find documentation for RGB, RGBA or PNG.

Upvotes: 4

Views: 2172

Answers (1)

DRz
DRz

Reputation: 1156

I have found how to do it:

Mono8 is just a table of pixel's value from 0 to 255 on a grayscale.
RGB is that same table according to other colors (Red, Green and Blue).

So, the same image has 3 times more values in RGB than in Mono8.
=> Repeat the same value for each pixel's component.

rgb = [ v for v in image_buffer for _ in range( 3 ) ]
rgb_ba = bytearray( rgb )
bitmap.FromBuffer( height, width, rgb_ba )

Thanks to Martijn Pieters for the help on the list comprehension!

Upvotes: 3

Related Questions