PXI

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving Data to an Image File

In C++ code I capture imagery from a frame grabber with

 

           errChk(imgGrab (Sid, &ImaqBuffer, TRUE))

 

where the declaration from ImaqBuffer is

 

                         static Int8         *ImaqBuffer=NULL .

 

Is there a simple way to save this to a PNG, JPG, or bitmap? Thanks.

0 Kudos
Message 1 of 8
(4,581 Views)

Have you looked at the shipping example code that comes with the vision software?  You should be able to find that on your computer at National Instruments » Vision » Text Based.  There are a lot of examples there to help you get started with IMAQ and C++.

 

The examples are an optional part of the IMAQ driver installation, so be sure that you have the support installed.

Jayme W.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 8
(4,570 Views)

Jayme:

 

     I have looked at the examples, but have not found any samples that save data captured from an NI frame grabber to a file. I need to save the data pointed to by ImaqBuffer and save it to a file; it would be great if you could point me to a working code segment. Thanks.

 

  Charles

0 Kudos
Message 3 of 8
(4,557 Views)

Hi,

 

So the first thing you need to do is make sure that you have installed text based support with your vision software.  This is not a default option during the installation you need to select to have this installed.  Once you do this the example can be found here:

 

C:\Program Files\National Instruments\Vision\Examples

 

In the MSVC folder there is an example called "Easy Acquire" that will show you how to capture an image.

 

You can also use the load image example but in your case it sounds like you want to use the save image function.

 

Regards,

 

Greg H.

Applications Engineer
National Instruments
0 Kudos
Message 4 of 8
(4,551 Views)

Hello Greg:

 

     Thanks for the response. I looked at the EasyAcquire code, and while it did not save the image, I was able to extract some of the code and write the following:

 

void saveImage()

    char name[64] ;  // Interface name
    char text[64] ;    // Diagnostics
    const Image* bi ;  // Image from NI frame grabber
    const char* fileName="C:\\Camera\\capture.bmp" ;
    RGBValue* colorTable = NULL;

    GetWindowText(HIntfName, name, 64) ;  // Get interface name

    sprintf(text, "%s  %s", name,fileName) ;  // Display interface name and filename to verify
    SetWindowText (HSerialOut, text) ;         // these variables are being set correctly

    bi=imaqEasyAcquire(name) ;  // Get image
    imaqWriteFile(bi, fileName, colorTable) ;  // Save to C:\Capture\capture.bmp

    if (bi != NULL) sprintf(text, "%s  %s  Done", name,fileName) ;  // All is well(?)
    else sprintf(text, "%s  %s  Image is null", name,fileName) ;    // otherwise tell me Image is null
    SetWindowText (HSerialOut, text) ;

}

 

The code correctly displays the interface name ("img0", same as used to display image) and the file name, but no file is saved. I also tried imaqWriteBMPFile and got the same results: no errors, diagnostic display looks good, but nothing is saved. Am I missing something?

 

  Charles

0 Kudos
Message 5 of 8
(4,547 Views)

Hi,

 

I would try the equivilant to the LV Write BMP file 2.  The function is called LV_WriteBMPFile.

 

void  LV_WriteBMPFile(void *SourceImage, const CStr FilePath, const void *ColorPalette, uint32_t Version, void *options, void *Error);

 

Regards,

 

Greg H.

Applications Engineer
National Instruments
0 Kudos
Message 6 of 8
(4,540 Views)

Greg:

 

     Could you point me to the documentation for this function; it was not in the NI-IMAQ or NI-Vision API reference manuals, and I did not find it on the web. I looked in niimaq.h and nivision.h and did not find it, so it looks like I need to add another refernce to my program, right? Which one? Thanks.

 

  Charles

0 Kudos
Message 7 of 8
(4,537 Views)

Charles,

 

That dll call is used in LabVIEW and is not in text based.  You can call the dll directly just as you would any other dll.

 

Other wise I would recommend using a C++ library to save files.

 

Regards,

 

Greg H.

Applications Engineer
National Instruments
0 Kudos
Message 8 of 8
(4,525 Views)