RGB32

RGB32 is a 32 bit color format. It is like RGB24, except that every pixel has an additional byte to store an alpha value. An alpha value describes the transparency of the pixel. Therefore, every pixel consists of 4 bytes. RGB32 is also referred to as RGBA, where the A stands for Alpha. The A value is not used in IC Imaging Control and is therefore always 0. As for the RGB24 pixel format, IC Imaging Control uses the BGRA byte order for the RGB32 pixel format. The organization of the pixels in the image buffer is from left to right and bottom up.

How to read and write pixel data

A video capture device, video format, FrameSnapSink must have been setup. The following code fragments show step-by-step how to access and manipulate the pixel data of RGB32.

First of all, we have to capture an image. Otherwise, the image buffer would be empty. To do so, live mode is started and FrameSnapSink.SnapSingle is called. This is all done by the GrabImage method.

Accessing the buffer

To access the bytes of the image buffer, we create an instance of BufferAccessHelper so you can write buf[column,line] to access the individual bytes.

In this example, we want to read out the first (upper left) two pixels of the image. In a second step we manipulate the first 3 pixels. Because RGB images are stored bottom-up, the index of the first line is lines-1.

To calculate the x-coordinate of the pixel data, the number of bytes required for one pixel (4) is multiplied with the column of the pixel to be retrieved. After that, an offset is added to access the red, blue or green component of the pixel.

[C#]
// RGB32is bottom-up, the first line has index lines-1 int y = frame.FrameType.Height - 1; txtOutput.Text = "Image buffer pixel format is RGB32\r\n"; txtOutput.Text += "Pixel 1: "; txtOutput.Text += "R=" + buf[0 * 4 + 2, y] + ", "; txtOutput.Text += "G=" + buf[0 * 4 + 1, y] + ", "; txtOutput.Text += "B=" + buf[0 * 4 + 0, y] + "\r\n"; txtOutput.Text += "Pixel 2: "; txtOutput.Text += "R=" + buf[1 * 4 + 2, y] + ", "; txtOutput.Text += "G=" + buf[1 * 4 + 1, y] + ", "; txtOutput.Text += "B=" + buf[1 * 4 + 0, y];

Manipulating Image Data

Instead of only reading pixel data, it is, of course, possible to manipulate the data as well. The following code sets the upper left hand pixel to red and the next 2 pixels to green and blue. After this manipulation, the image is saved as a .bmp file.

[C#]
// Set the first pixel to red (255 0 0) buf[0 * 4 + 2, y] = 255; buf[0 * 4 + 1, y] = 0; buf[0 * 4 + 0, y] = 0; // Set the second pixel to 128 (gray) buf[1 * 4 + 2, y] = 0; buf[1 * 4 + 1, y] = 255; buf[1 * 4 + 0, y] = 0; // Set the third pixel to 255 (white) buf[2 * 4 + 2, y] = 0; buf[2 * 4 + 1, y] = 0; buf[2 * 4 + 0, y] = 255; TIS.Imaging.FrameExtensions.SaveAsBitmap(frame, "RGB32.bmp");

To check the result, open the saved image and take a look at the upper left hand pixels. They should look as follows:

image

<< Accessing an Image Buffer