?
Solved

Checking valid Image File.

Posted on 2008-02-12
4
Medium Priority
?
208 Views
Last Modified: 2012-08-13
Hi,

I need to check a valid image file like jpg, png, bmp and etc.

Please help how to do it.

Thank you.
0
Comment
Question by:emi_sastra
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Jorge Paulino
ID: 20873156
Hi emi_sastra,

You can do something like:

Dim fi As New FileInfo(MyFileFullPath)
If fi.Extension = ".bmp" Or fi.Extension = ".jpg" Or fi.Extension = ".png" Then
  ' valid file
End If

Of couse someone could rename to that but if thats the case you can try to load it (in a different function using a error handling tho catch error) and check if it's valid. But this is heavy for the your application/system.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 20873258
Hi,

I don't care its extension and I've already check its existing.
Could you please provide code how to check it as you mentioned?

Thank you.
0
 
LVL 48

Accepted Solution

by:
Jorge Paulino earned 2000 total points
ID: 20873311
Try this:

Private Function ValidPicture(ByVal filename As String) As Boolean
  Dim pb As PictureBox

  Try
      pb.Load(filename)
     Return True
 
  Catch ex As Exception
     Return False
  Finally
    pb.Dispose()
  End Try
End Function

End Function


Then you can use it this way:

If ValidPicture("c:\abc.bmp") Then
  ' valid picture
End If

Hope this helps
jpaulino
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 20873322
Hi,

Thank you very much for your help.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question