Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Save bitmap on disk C++

I want to save a bitmap on my hard disk with MSVC. I just saw on the web site that I should use imgSessionSaveBufferEx but there is no informations and examples of it. I tried:

imgSessionSaveBufferEx (Sid, (void *)ImaqBuffer, "test");

It doing nothing, where is my image?

Thank you.
0 Kudos
Message 1 of 4
(4,686 Views)
Hello,

If you are using the NI IMAQ driver, you are correct. The function used to save an image is imgSessionSaveBufferEx. The format for this function is shown below, but is outlined much more clearly in the NI IMAQ Function Reference Manual, which should be installed with the NI IMAQ driver when you include support for C++ or VB.


imgSessionSaveBufferEx saves a buffer of a session to disk in bitmap, TIFF, or PNG format.

rval = imgSessionSaveBufferEx(SESSION_ID sid, const void* buffer, const char* fileName);


Parameters (name, type, input/output)

sid SESSION_ID input
buffer const void* input
fileName const char* input
rval Int32 output



Hope this helps!

Robert
0 Kudos
Message 2 of 4
(4,668 Views)


@cural wrote:
I want to save a bitmap on my hard disk with MSVC. I just saw on the web site that I should use imgSessionSaveBufferEx but there is no informations and examples of it. I tried:

imgSessionSaveBufferEx (Sid, (void *)ImaqBuffer, "test");

It doing nothing, where is my image?

Thank you.


Hi,

Not too sure if this would works... but i think you would need to change the "test" to "test.bmp" or someother extension like .png etc... the type needed by the function
0 Kudos
Message 3 of 4
(4,666 Views)

Hi everyone,

                   I have got a big problem, by using the  memory allocation function call malloc(), i have been able to store in the allocated address. But when i load from the allocated memory address, it loads only last image not from the begining in sequence. Could you tell me what is the problem. here is the code. These are the sample that i have been trying to use.

void

ImaqThread(LPDWORD lpdwParam,char *alloc)

{

long n=0,m;

long j=0;

int i=0,l=1264,k=0;

char *mac;

char *buf;

char *b[3];

char buffer[32];

char filename[17];

//char file[17];

static int t1, t2;

static int nbFrame = 0, error;

// Create a pointer to the stop boolean. This needs to be

// volatile because the value can change at any time.

BOOL*

volatile stop = (BOOL*)lpdwParam;

alloc = (

char*)malloc(sizeof(char));

if (alloc==NULL)

{

exit (1);

}

while(!*stop && !error)

{

t2 = GetTickCount();

// Get the frame after tne next Vertical Blank

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

*alloc=ImaqBuffer;

alloc[1]=

'\0';

k++;

alloc=alloc+2;

if (k==2)

{

alloc=alloc-2;

loop:

*ImaqBuffer=alloc;

sprintf (filename,

"c:\\tmp\\%4.4d.bmp", j);

j++;

imgSessionSaveBufferEx(Sid,(

void *) ImaqBuffer,filename);

alloc[0]=

"0";

//free(alloc);

alloc=alloc-2;

goto loop;

}

}

Error:

if(error<0 && !*stop)

{

DisplayIMAQError(error);

PostMessage(ImaqSmplHwnd, WM_COMMAND, PB_STOP, 0);

}

return 0;

}

0 Kudos
Message 4 of 4
(4,323 Views)