Hi All,
I need the image data as buffer of bmp/jpeg/png images so, i can
convert the RGB888 data into RGB565 data buffer.For this i am using
the following approach. Its working fine with the JPEG and PNG (24
bit) images
bitmap = wx.Bitmap(bmpFilePath, wx.BITMAP_TYPE_BMP)
bitDepth = bmp.GetDepth()
if bitDepth == 24:
bpp = 3 # bytes per pixel
buffer_length = bmp.GetWidth() * bmp.GetHeight() * bpp
src_buffer = array.array('B', [0] * buffer_length )
bmp.CopyToBuffer(buffer, wx.BitmapBufferFormat_RGB)
bitmap_array = ctypes.c_ushort * (bitmap.GetWidth() *
bitmap.GetHeight())
target_arr = bitmap_array()
for counter in range (0, buffer_length, bpp):
if bpp == 3:
r = buffer[counter]
g = buffer[counter + 1]
b = buffer[counter + 2]
# Convert from RGB888 to RGB565
arr[count] = (((r>>3)<<11) | ((g>>2)<<5) | (b>>3))
count += 1
This code is not working for bmp image with the 24 bit depth and
throwing following error.
return _gdi_.Bitmap_CopyToBuffer(*args, **kwargs)
RuntimeError: Failed to gain raw access to bitmap data.
Any help really apprecaible.