|
-
Feb 16th, 2010, 07:10 PM
#1
Thread Starter
New Member
Fast way to check if an image file (JPG, BMP, etc) is viewable?
Hi all,
Just looking for a fast way to check a graphics file to make sure it's not corrupted. I tried using LoadPicture with an Image control (and trapping errors to detect if the file is bad) but it's slooooow.
Any ideas would be appreciated.
Thanks!
Fox
-
Feb 16th, 2010, 07:32 PM
#2
Re: Fast way to check if an image file (JPG, BMP, etc) is viewable?
Welcome to the forums.
The alternative may not be faster. You would have to parse the image file manually. And that is what VB is doing before it loads the image.
JPGs & GIFs being compressed, will be much more complicated to parse.
Bitmaps are relatively easy to determine if they are corrupt or not.
But if you are also talking about icons, cursors, wmfs, emfs, and GIFs then you'd need manual parsers for each of them too.
If you are loading the image into a visible object (like a form, picbox, image control) then that will take more time because VB is displaying it after loading it.
-
Feb 16th, 2010, 07:52 PM
#3
Thread Starter
New Member
Re: Fast way to check if an image file (JPG, BMP, etc) is viewable?
Thanks for your reply LaVolpe.
I've set my Image control Visible=False, does that make any difference?
What about an external DLL/library to use for loading the images, would anything (free out there be faster than internal VB6 code?
Thanks again,
Fox
-
Feb 16th, 2010, 08:09 PM
#4
Re: Fast way to check if an image file (JPG, BMP, etc) is viewable?
Hmmm, maybe it isn't the testing that is slow but other processes. VB can load images quite fast. And though some may not be viewable in VB it doesn't mean it is corrupted. For example, VB has real problems with modern day icons, but the icons are not corrupted. VB can't display PNG/TIFF natively but it doesn't mean the image is corrupted.
If you give us more details of what you are trying to do and how you are doing it, we may be able to give better advice.
Edited: Regarding DLLs, there are several; here are 2 free ones. GDI+ that comes with XP & above and free download with 98 & above from MSDN. FreeImage library is another; there's examples of its usage in the Code Bank section. Simply search there for FreeImage. But answering my question may be the best answer . Remember what I said above; even if those other DLLs say it is a valid image format, doesn't mean VB can load it.
Last edited by LaVolpe; Feb 16th, 2010 at 09:01 PM.
-
Feb 16th, 2010, 11:34 PM
#5
Frenzied Member
Re: Fast way to check if an image file (JPG, BMP, etc) is viewable?
Hmmm... this might work for you...
Code:
Public P As StdPicture
Public Function CanLoadPicture(PathToPic) As Boolean
On Error GoTo CanLoadPictureError
Set P = LoadPicture(PathToPic)
CanLoadPicture = True
Exit Sub
'if we are here then there was an error...
End Sub
So no delay in the rendering of the graphic and if you want to display it then...
Code:
Image1.Picture = P
'Picture1.Picture = P
Good Luck
Option Explicit should not be an Option!
-
Feb 17th, 2010, 12:03 AM
#6
Re: Fast way to check if an image file (JPG, BMP, etc) is viewable?
 Originally Posted by vb5prgrmr
Code:
Public P As StdPicture
Public Function CanLoadPicture(PathToPic) As Boolean
On Error GoTo CanLoadPictureError
Set P = LoadPicture(PathToPic)
CanLoadPicture = True
Exit Sub
'if we are here then there was an error...
End Sub
On an unrelated note, this is exactly the kind of logic where On Error Resume Next is better than On Error Goto Label.
vb Code:
Public Function CanLoadPicture(PathToPic) As Boolean
On Error Resume Next
Set P = LoadPicture(PathToPic)
If Err.Number = 0
' Worked fine
Else
' There was an error
End If
End Sub
Better structure this way.
-
Feb 17th, 2010, 07:59 AM
#7
Frenzied Member
Re: Fast way to check if an image file (JPG, BMP, etc) is viewable?
Opinion!... and you always return false...
Option Explicit should not be an Option!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|