IMAQ GetImagePixelPtr Example

LabView NI Vision

IMAQ GetImagePixelPtr Example

The following figure illustrates a typical implementation scheme for IMAQ GetImagePixelPtr.

This VI enables the user to set an image size in LabVIEW. The VI then gets the pixel pointer, line width, image width, and image height.

Note  The line width is the width, in pixels, of an image including the image border.

The Call Library Function Copy_C_Image_To_LabVIEW_Image takes in the above parameters, fills a C image with user-defined data, and copies the data to the LabVIEW image. When Copy_C_Image_To_LabVIEW_Image finishes execution, the LabVIEW image contains the data that the C code calculated.

The C code calculates the following:

#include <ansi_c.h>
#include <nivision.h>

//==============================================================================
//
//  Copy_C_Image_To_LabVIEW_Image   -   Creates a C image, fills it with the value
//                                      128, and copies it to a passed LV image
//                                      which is then returned to the calling VI.
//
//  Parameters:
//      LVImagePtr         -   the passed LV image
//      LVLineWidth        -   the width (including the border) of the passed LV image
//      LVWidth            -   the width (excluding the border) of the passed LV image
//      LVHeight           -   the height of the passed LV image
//
//==============================================================================
void __declspec(dllexport) __stdcall Copy_C_Image_To_LabVIEW_Image (char* LVImagePtr, int LVLineWidth,
int LVWidth, int LVHeight) 
{
ImageInfo testImageInfo;
Image *testImage;
int y;
PixelValue pixelValue;

// Create the image as IMAQ_IMAGE_U8
testImage = imaqCreateImage (IMAQ_IMAGE_U8, 3);

// Set the image size
imaqSetImageSize (testImage, LVWidth, LVHeight);

// Fill the image with 128's
pixelValue.grayscale = 128;
imaqFillImage (testImage, pixelValue, NULL);

// Get the image info -- this should be that same as the height and width 
// the image was created from
imaqGetImageInfo (testImage, &testImageInfo);

// Copy, line by line, the C image into the LV image.
for (y=0; y<LVHeight; ++y) {
    memcpy (LVImagePtr + y * LVLineWidth, (char*)testImageInfo.imageStart +
    y * testImageInfo.pixelsPerLine, LVWidth);
}

// Dispose of the C image
imaqDispose(testImage);
}