PDA

View Full Version : How to get create bitmap from RGB24



Morgane
March 25, 2015, 16:08:07
Hi,

I'm using a DFK 23G445 Camera using the RGB24 (1280x960) video format.
I am getting the byte[] from the ImageBuffer result and I need to create a bitmap according to this byte[].
The problem is that I am getting a flipped image.

In the documentation, it says "As for the RGB24 pixel format, IC Imaging Control uses the BGRA byte order for the RGB32 pixel format." so I was using the BGR24 format (bgra24 does not exist in the System.Windows.Media).

I am getting this result via ICapture:
1764

And the result using my software:
1766

Here the code where I am creating the byte[]:


pixelFormat = System.Windows.Media.PixelFormats.Bgr24;
int size = buffer.FrameType.BufferSize;
byte[] img = new byte[size];
Marshal.Copy(buffer.GetImageDataPtr(), img, 0, size);



And here the code where I create the Bitmap:


int stride = width * (pixelFormat.BitsPerPixel / 8);
image = BitmapSource.Create(width,
height,
96,
96,
pixelFormat,
BitmapPalettes.Gray256Transparent,
img,
stride);


Do you know why this flip happens ?
Am I doing something wrong ?

Stefan Geissler
March 30, 2015, 11:56:24
Hello

In case you want to save the bitmap files to hard disc, you can use the "save" function of the Memorybuffer class:
http://www.theimagingsource.com/en_US/support/documentation/icimagingcontrol-class/meth_descMemBuffer_save.htm

RGB32 is ABGR ordered in memory, RGB24 is BGR order

In order to flip the image, multiply the image height with -1. I believe, this helps.

Morgane
April 1, 2015, 21:57:43
Hello

In case you want to save the bitmap files to hard disc, you can use the "save" function of the Memorybuffer class:
http://www.theimagingsource.com/en_US/support/documentation/icimagingcontrol-class/meth_descMemBuffer_save.htm

RGB32 is ABGR ordered in memory, RGB24 is BGR order

In order to flip the image, multiply the image height with -1. I believe, this helps.

Hi,

Thank you for your answer.
What do you mean by "multiply image height with -1" ?
Do you have an efficient way to invert the image (basically do you only provide only an upside down pointer ?) or does byte by byte is my only solution?

Thank you for your help.


Morgane

Stefan Geissler
April 2, 2015, 09:05:57
Hi

"multiply" means the simple mathematical thing:


image = BitmapSource.Create(width,
height * -1,
96,
96,
pixelFormat,
BitmapPalettes.Gray256Transparent,
img,
stride);

Stefan Geissler
April 2, 2015, 09:05:58
Hi

"multiply" means the simple mathematical thing:


image = BitmapSource.Create(width,
height * -1,
96,
96,
pixelFormat,
BitmapPalettes.Gray256Transparent,
img,
stride);