LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Displaying imaq image in canvas

Hallo,
I am using LabWindows/CVI 8.0.1 with IMAQ Vision 8.0 on Windows XP and have the following problem:
 
My program obtains a single frame from an AVI file using "imaqReadAVIFrame" and displays it with the "imaqDisplayImage" function. So far this works fine. I would prefer to display the image in a canvas of a panel. To do so the program uses the following function:
 
void DisplayFrameInCanvas( const Image *frame )
{
 int bmp_id = 0;
 int is_available = 0;
 
 imaqImageToClipboard( frame, NULL );
 ClipboardGetBitmap( &bmp_id, &is_available );
 if ( is_available == 1 )
 {
  CanvasDrawBitmap( panelHandle, PANEL_CANVAS, bmp_id, VAL_ENTIRE_OBJECT, VAL_ENTIRE_OBJECT );
  DiscardBitmap( bmp_id );
 }
 else
 {
  SetCtrlAttribute (panelHandle, PANEL_CANVAS, ATTR_PEN_COLOR, VAL_RED);
  CanvasDrawTextAtPoint (panelHandle, PANEL_CANVAS, "no bitmap available", VAL_APP_META_FONT, MakePoint(5,5), VAL_UPPER_LEFT);
 }
}
 
This function copies the image into the clipboard using "imaqImageToClipboard", retrieves the bitmap from the clipboard using "ClipboardGetBitmap" and finally draws the bitmap on the canvas using "CanvasDrawBitmap". When browsing through the avi file and loading and displaying each frame one after the other the program will sometimes work as supposed and display the bitmap in the canvas and sometimes it complains that no bitmap is available in the clipboard. To be precies it occures more often that no bitmap is available in the clipboard than one is available.
 
As the program works fine when using the "imaqDisplayImage" function I assume that there is no problem with obtaining single frames from the avi file and providing it to the various funcions using it. This also makes me believe that it is not the avi file that is the cause for this effect. This strange behaviour occures while the program is running (it is not a question of whether the program is started and it works and when it is shut down and started a second time and it does not work anymore).
 
Having used exactly the same function with LabWindows/CVI 7.0 and IMAQ Vision 6 installed on a Windows 2000 system I had not problems with displaying an image in a canvas in the described way.
 
Thus my question: Why would there sometimes be no bitmap available in the clipboard?
 
I hope I could describe my problem clear enough.
 
Regards
Thomas
 
 
0 Kudos
Message 1 of 3
(3,355 Views)

I have seen Windows fail to put something in the clipboard when requested, if it is having to work hard at swapping memory in and out of its pagefile. Perhaps the function imaqImageToClipboard( frame, NULL ); you mention has an error return value that you could check?

JR

0 Kudos
Message 2 of 3
(3,323 Views)

Hallo JR,

I did as you recommended and checked the error codes of all functions involved. I now believe that the problem can be narrowed down to the "imaqImageToClipboard" function. In the case a bitmap cannot be displayed in the canvas "ClipboardGetBitmap" says that in fact that there is no bitmap available in the clipboard (second function parameter "Available" is 0). This is despite the fact that copying the image to the clipboard seems to has succeeded ("imaqImageToClipboard" returns with "no error").

I have experimented with using "ProcessSystemEvents" and "ProcessDrawEvents" functions before and after calling the "imaqImageToClipboard" function finding that when using "ProcessSystemEvents" immediately after "imaqImageToClipboard" all images are displayed in the canvas. But I would think that it is not the intention to slow down the program by being obliged to use these two functions together to make the program work properly. Or is there another - may be faster - way of displaying an "Image *image" in a canvas?

Thanks for your help.

Thomas

0 Kudos
Message 3 of 3
(3,318 Views)