View Full Version : Imaging processing by using C#

December 15, 2004, 19:06:12
Hi, I am using IC2.1 with Windows Visual c#. I just want to the procedures for grabing a image and how to access the grabed data. I don't know whether I am right:
1 device.LiveStart()
2 declare variable: byte* buffer
3 device.memorysnapimage()
4 Then where did the memorysanpimage snap the image to?

If you have a complete sample that does grabing and simple imaging processing, that would be great.

Thanks a lot.

Stefan Geissler
December 16, 2004, 14:46:57

With IC Imaging Control comes an image processing C# sample.

After you have called MemorySnapImage, you can access the image data as follows:

TIS.Imaging.ImageBuffer ImgBuffer;
int x, y;
int BytesPerLine;

ImgBuffer = icImagingControl1.ImageActiveBuffer;

byte* pDatabyte = ImgBuffer.GetImageData();

The pointer in pDatabyte points to the first byte of the first pixel of the image in the lower left corner. If you use an RGB 24 sinktype, which is the default one, pDatabyte points to the blue value of the first pixel.
You can access the value by writing
int blue = (int)*pDatabyte;
int blue = (int)pDatabyte[0];

To access the next byte, you can simply write

The ++ method is faster, because only the pointer is incremented by one.

January 21, 2005, 02:59:20
What is the best method for GetPixel on a 24bit RGB image?

Stefan Geissler
January 21, 2005, 09:30:55

As i wrote in my last post, you retrieve the pointer to the image data as shown in the code snippet.
If you want to access the pixel by col/row coordinates, you may calculate the index in the byte stream of the RGB24 image as follows:

index = (row * imagewidth + col) * 3

blue = (int)pDatabyte[index];
green = (int)pDatabyte[index+1];
red = (int)pDatabyte[index+2];

the “3” is used, because we have 3 bytes per pixel. This is the way, i would access the pixels.