Loading
 
Support Support Home » APIs » XiAPINET » Accessing xiAPINET pixel data in NET Bitmap

Accessing xiAPI.NET pixel data in .NET Bitmap

Overview

This article describes how to access pixel data in a .NET Bitmap image acquired in xiApi.NET.

Implementation

First we have to acquire the bitmap image with the proper GetImage function.

Bitmap myImage;
int timeout = 1000;

xiCam myCam = new xiCam();
myCam.OpenDevice(0);
myCam.StartAcquisition();
// Acquire a new bitmap.
myCam.GetImage(out myImage, timeout);

Then we have to lock the bitmap data with the BitmapData Class.

// Lock the bitmap's bits. 
Rectangle rect = new Rectangle(0, 0, myImage.Width, myImage.Height);
System.Drawing.Imaging.BitmapData imgData = myImage.LockBits
(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, myImage.PixelFormat);

Now you can access the pixel data in the first line of the image.

// Get the address of the first line.
IntPtr ptr = imgData.Scan0;
/*
   Your processing here
*/

When you have finished processing the pixel data, unlock the data and close the camera.

// Unlock the bits.
myImage.UnlockBits(bmpData);

myCam.StopAcquisition();
myCam.CloseDevice();