Detecting if a filename is a valid picture file 
Author Message
 Detecting if a filename is a valid picture file

Hi-

  I'm using VB5 and I want a very fast way of determining if a given
filename would cause problems if loaded into a standard Image control
(i.e. that it's not a text file or .WAV file or a corrupted .JPG, etc).
I have a sub that uses On Error and tries loading the file into a
temporary Image control, but that method is too slow (although it works
great).  There may not be any other way.

Thanks!
Brad Stone
The Salinon Corp.



Mon, 14 Jan 2002 03:00:00 GMT  
 Detecting if a filename is a valid picture file
Maybe

Dim picfile As StdPicture
OnError Resume Next
Set picFile=LoadPicture(<filename>)
If Err.........

Quote:
>Hi-

>  I'm using VB5 and I want a very fast way of determining if a given
>filename would cause problems if loaded into a standard Image control
>(i.e. that it's not a text file or .WAV file or a corrupted .JPG, etc).
>I have a sub that uses On Error and tries loading the file into a
>temporary Image control, but that method is too slow (although it works
>great).  There may not be any other way.

>Thanks!
>Brad Stone
>The Salinon Corp.



Mon, 14 Jan 2002 03:00:00 GMT  
 Detecting if a filename is a valid picture file
You can quickly detect whether it is, in fact, an image file (but not that
it's not corrupted farther down) by examining the headers.  For instance, a
bitmap file always starts with the two bytes &H4D42 ("BM") and a gif is
similar but I forget exactly.  You can look up all sorts of file formats at
www.wotsit.org

Jim Deutch
MS Dev MVP

Quote:

>Hi-

>  I'm using VB5 and I want a very fast way of determining if a given
>filename would cause problems if loaded into a standard Image control
>(i.e. that it's not a text file or .WAV file or a corrupted .JPG, etc).
>I have a sub that uses On Error and tries loading the file into a
>temporary Image control, but that method is too slow (although it works
>great).  There may not be any other way.

>Thanks!
>Brad Stone
>The Salinon Corp.



Mon, 14 Jan 2002 03:00:00 GMT  
 Detecting if a filename is a valid picture file
ImgX at http://DesignerControls.com determines the type of file before
reading it.  If the file is not a known image format, it won't open it.  It
is very quick.


Quote:
> Hi-

>   I'm using VB5 and I want a very fast way of determining if a given
> filename would cause problems if loaded into a standard Image control
> (i.e. that it's not a text file or .WAV file or a corrupted .JPG, etc).
> I have a sub that uses On Error and tries loading the file into a
> temporary Image control, but that method is too slow (although it works
> great).  There may not be any other way.

> Thanks!
> Brad Stone
> The Salinon Corp.



Tue, 15 Jan 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. DOS wildcard, *, not valid with .FileName?

2. valid filenames for shell functions?

3. Valid Filenames?

4. Checking for valid filename

5. Converting an invalid filename to a valid one

6. check string as valid filename

7. API to test for valid filename?

8. Valid FileName

9. Detecting whether an object reference points to nothing or to a valid object

10. Detecting Valid Connection To Device

11. The file is not a valid compound file Error

12. how to detect if I am connected?

 

 
Powered by phpBB® Forum Software