03-26-2012 06:07 PM
Greetings,
I am trying to load a canvas control programatically with a user-selected file,
I assume that there is a way to do this because I can do a Load Image from the control editor and that works.
It seems that there is a function call to do this that I just cannot find.
I thought that it would be SetCtrlAttribute(panel, ctl, ATTR_IMAGE_FILE, fileName);
But when I do that I get the error:
NON-FATAL RUN-TIME ERROR: "Test.c", line 55, col 18, thread id 0x000000C0: Library function error (return value == -46 [0xffffffd2]). The attribute passed is not valid.
The definition of fileName is:
char fileName[500]; and that is retrieved from a FileSelectPopup.
I am assuming that IMAGE_FILE is not a valid attribute for a canvas control.
Any help is appreciated.
THanks
03-26-2012 11:59 PM
To draw an image onto a canvas control you can use CanvasDrawBitmap function, passing in the handle of a bitmap image in memory: refer to the online help for some guidance on function parameters.
In case of doubts on some control it's a good habit to make reference to the online help: right click on the control in the UIR editor and select Control Help: you'll see a page with links to control attributes, functions, events that apply to it and a general page with details on programming on that control. This procedure is valid for every control CVI offers you and is a powerful resource to use: the links I added to this post show the corresponding help pages for the canvas control.
03-27-2012 09:16 AM
Thanks for the feedback and I have seen posts related to using a bitmap.
However, since the Load Image button will accept a .JPG file for display, it seems to me that I should be able to just load an image.
Is there not a direct way to just load a file?
Jacob
03-27-2012 09:25 AM
You can combine the two functions GetBitmapFromFile and CanvasDrawBitmap
03-27-2012 09:31 AM
Be aware that "bitmap" here is not a synonim of "BMP file": GetCtrlBitmap can load image files in several formats, including .JPG