LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

unable to save valid tif with imaq1394SaveBuffer()

Hi.
 
I am developing an application to capture images using the NI-IMAQ for IEEE 1394 Camera API.  I am using Microsoft Visual Studio (C++) 7.1 on Windows XP.
 
I call imaq1394Snap() passing it a valid session id, previously allocated buffer, and Rect object.  Here is the buffer:
   unsigned char *buffer;
   buffer=new unsigned char[bufferSize];
 
The buffer I get is valid and contains the correct data for the image captured.  (I tested this out with other software and was able to view the image data.)
 
The problem arises when I try to save the buffer as a .tif image with the imaq1394SaveBuffer() method.
  int rval=imaq1394SaveBuffer(sid, buffer, "image.tif");
The method seems to work and rval==IMG1394_ERR_GOOD.  However, the resulting .tif file is not valid; it won't open and is only 1KB.  I also tried to save as .bmp, .jpg, and .png files, but these did not work (bmp and jpg do not save, png crashes the program).  What is the right way to save a buffer as a .tif image?
 
Thanks in advance for any help or advice!
0 Kudos
Message 1 of 4
(3,202 Views)
Hello,

One problem may be that you are passing a char * when the function is looking for a void pointer. 
//the function help has the prototype like this
rval = imaq1394SaveBuffer (SESSION_ID sessionId, void *buffer, char* filename);

Try casting your buffer as a void * like this:

static char *       ImaqBuffer=NULL;
ImaqBuffer=new unsigned char[bufferSize];
retVal = imaq1394SaveBuffer(Sid, (void *)ImaqBuffer, "test.bmp");

Also, the function help for Version 2.0.2 says that the supported formats are BMP, PNG, and JPG, so I don't think you'll be able to create .TIF image.

Hope this helps.
S. Arves S.
National Instruments
Applications Engineer
0 Kudos
Message 2 of 4
(3,191 Views)
Actually, I fixed my problem. I hope.
 
I think the API has a typo because it seems like the method actually wants a void ** buffer, so I cast it as that.  Also, the beginning page of the API which lists all the functions says that it is ok to save TIF images (even though the method's API page does not list TIF).  And, it's working so far.
 
For the Snap method, I had passed a Rect r={0,0,0,0} as the Rect object since that is what the sample code does.  When I changed it to Rect r={0,0,width,height} it seemed to work.  I'm not sure if that is the reason why it wasn't working though.  But, hopefully, it is fixed now.  Thanks for the response.
0 Kudos
Message 3 of 4
(3,185 Views)
I just tested passing as a void ** and as a void * and they both work.  Anyhow, I'm glad to hear it's up and working for you.
S. Arves S.
National Instruments
Applications Engineer
0 Kudos
Message 4 of 4
(3,183 Views)