Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Ammar Hadi
  Where is Ammar Hadi?
 Al-Samawah
 Iraq
 Ammar Hadi
 To: JaiPrakash Bhandari
  Where is JaiPrakash Bhandari?
 Hyderabad
 India
 JaiPrakash Bhandari
 Tags
Subject: RE: Not loading image on Image control
Thread ID: 249073 Message ID: 249124 # Views: 2 # Ratings: 1
Version: Visual FoxPro 9 Category: Forms
Date: Monday, December 28, 2009 11:45:47 PM         
   


> Hello
> I have an Image control on a form and user selects an image file through GETFILE() option.
> But, we know that there are some image files(such as Bitmap, Png, etc), which does not have any Preview or of not correct/valid image files. In that particular case, the Image is not showing on the Forms Image control(means not loading the image properly), instead it's showing the Image control like in design view(with crossed lines).
> Those Image files, if open from Explorer, generally shows "No Preview available". This type of files are easily available from '%Temp%' folder.
> Is there any way to detect those files and to prevent from showing the Image control as in design view ?
>
> Regards
> Bhandari

Hello Bhandari.

I have a twist for you .. I hope it helps.

The idea is to use a test by resizing the image to be very small (unrealistic value) like width and height equal to 1, then to use the Stretch property to 0 (clip) and then you load the picture. If the image is invalid, the dimensions of the image control will stay at 1 pixel while if it is valid it will resize. Then reset the width, height and Stretch properties to its original values. This way you will know when the image is invalid and do what you want like showing a blank image or anything else.

See this code:

LOCAL lcPic, lnStretch, lnHeight, lnWidth

WITH THISFORM.image1

  * saving initial settings
  lnStretch=.STRETCH
  lnHeight=.HEIGHT
  lnWidth=.WIDTH

  * getting the file to show
  lcPic=GETFILE()

  * testing the file
  .PICTURE=""
  .HEIGHT=1
  .WIDTH=1
  .STRETCH=0 && Clip

  .PICTURE=lcPic

  IF .WIDTH=1
    * this means the pic failed to be shown, show the default empty pic
    .PICTURE="D:\Documents\Visual FoxPro Projects\POS\Project Files\Pictures\Blank.jpg"
  ENDIF

  * reset the origional settings
  .HEIGHT=lnHeight
  .WIDTH=lnWidth
  .STRETCH=lnStretch

ENDWITH


regards.

Ammar Hadi ................IRAQ

My Foxite Weblog

The Most Beautiful View ... is the one I Share with You.
--------------------------------------

ENTIRE THREAD

Not loading image on Image control Posted by JaiPrakash Bhandari @ 12/28/2009 8:21:20 AM
RE: Not loading image on Image control Posted by Stefan Wuebbe @ 12/28/2009 10:09:53 AM
RE: Not loading image on Image control Posted by Ammar Hadi @ 12/28/2009 11:45:47 PM