P
Paul Loveless
Hi all, I've written the following code to retrieve the file format of an
image file:
Dim objImageFormat As ImageFormat
objImageFormat = Me.SourceImage.RawFormat
If objImageFormat.Equals(Imaging.ImageFormat.Bmp) Then
Me.ImageFormat = "BMP"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Emf) Then
Me.ImageFormat = "EMF"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Exif) Then
Me.ImageFormat = "EXIF"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Gif) Then
Me.ImageFormat = "GIF"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Icon) Then
Me.ImageFormat = "ICON"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Jpeg) Then
Me.ImageFormat = "JPEG"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Png) Then
Me.ImageFormat = "PNG"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Tiff) Then
Me.ImageFormat = "TIFF"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Wmf) Then
Me.ImageFormat = "WMF"
Else
Me.ImageFormat = "Unknown"
End If
Although this works, I would like to know if there is a better way than
having all these "if" statements. In addition, if new formats were added, I
would have to add the new format to the list. Is there a way of writing the
code so that it would automatically pick up any new formats.
Regards,
Paul
image file:
Dim objImageFormat As ImageFormat
objImageFormat = Me.SourceImage.RawFormat
If objImageFormat.Equals(Imaging.ImageFormat.Bmp) Then
Me.ImageFormat = "BMP"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Emf) Then
Me.ImageFormat = "EMF"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Exif) Then
Me.ImageFormat = "EXIF"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Gif) Then
Me.ImageFormat = "GIF"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Icon) Then
Me.ImageFormat = "ICON"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Jpeg) Then
Me.ImageFormat = "JPEG"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Png) Then
Me.ImageFormat = "PNG"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Tiff) Then
Me.ImageFormat = "TIFF"
ElseIf objImageFormat.Equals(Imaging.ImageFormat.Wmf) Then
Me.ImageFormat = "WMF"
Else
Me.ImageFormat = "Unknown"
End If
Although this works, I would like to know if there is a better way than
having all these "if" statements. In addition, if new formats were added, I
would have to add the new format to the list. Is there a way of writing the
code so that it would automatically pick up any new formats.
Regards,
Paul