SalPicSetFile and invalid picture type

forum.sourcecode (2000-2005) & forum.td.sourcecode (2005-2010)
David Lein

SalPicSetFile and invalid picture type

Post by David Lein » 28 May 2008, 20:50

 Posted by:  David Lein 

Hello all,

If I use the following lines of code to read a picture bitmap into a window
and the embedded format of the sBMPPhoto is not truly a bitmap the
SalPicSetFile will lock the file until the application exits. Is there a
way to check what the embedded file type is (example: jpeg, bmp, exe ... )
beforehand so I don't read in an incorrect file type? I've tried using
SalPicGetDescription but have had no success other than a null string
returned.

Code: Select all

If (SalStrRightX(SalStrLowerX(sBMPPhoto), 4) = '.bmp')
   Call SalPicSetFile(hWndPhoto, sBMPPhoto)
   Call SalUpdateWindow(hWndPhoto)
   Call VisFileDelete(sBMPPhoto)
Regards

Dave

James McCall

Re: SalPicSetFile and invalid picture type

Post by James McCall » 29 May 2008, 07:11

 Posted by:  James McCall 

Hey, you're right, it does lock it and not only using SalPicSetFile( ). TD
is (or was) distributed with the ImageMan library so I tried using the
ImageMan function ImgGetInfo( ) to see if that could be used to determine
the real file type. I didn't find it useful but I did notice that it also
locks the file.

My software uses the LeadTools libraries. The L_FileInfo( ) function does
not fall for the "incorrect extension bluff" and tells you the correct file
format but I guess that's not an option for you.

For what it's worth, if you load the image using ImageMan then it will at
least display in the picture control - which is more than
SalPisSetFile(hWndPhoto,sBMPPhoto) will do.

David Lein

Re: SalPicSetFile and invalid picture type

Post by David Lein » 29 May 2008, 20:58

 Posted by:  David Lein 

Here was my solution to this:

I opened the file in binary mode, read the file into a long string, then
called SalPicSetString. This doesn't lock the file so once I read in my
bitmap (or whatever embedded file type it is) I can delete the existing
file. When the embedded file is not a bitmap (ie: jpg, exe) the picture
handle (hWndPhoto) will display blank.

James McCall

Re: SalPicSetFile and invalid picture type

Post by James McCall » 30 May 2008, 17:42

 Posted by:  James McCall 

Having said previously that the ImageMan functions lock the file as well,
I'm not so sure now. I just went and tried it again and it works OK. I
don't have the inclination to figure out if I was wrong yesterday or today!

So if you want the image to show even if it isn't a real BMP (and not get
locked) then you should try ImageMan. It is encapuslated in the extended
SAL library, in function SalPicSetFileX. So you don't even need to know
anything about ImageMan unless you want to shrink to fit, which requires a
few more lines of code.

James

Return to “td.sourcecode”

Who is online

Users browsing this forum: [Ccbot] and 0 guests