画像の形式には、GIF,JPEG,PING,BMP,TIFFなどさまざまな形式があります。
ここでの例は、拡張子ではなくファイル内の内部情報から画像の種類を判定します。
Public Function GetImageType(ByVal strFile As String) As String
Dim ic As System.Drawing.Imaging.ImageCodecInfo
Dim bmpSrc As New Bitmap(strFile)
For Each ic In System.Drawing.Imaging.ImageCodecInfo.GetImageDecoders()
If ic.FormatID = bmpSrc.RawFormat.Guid Then
Return ic.FormatDescription
End If
Next
Return String.Empty
End Function
Bitmapオブジェクトが生成されると画像の種類も判定されており、そのGUIDから 画像の種類を返します。
Copyright 1997-2010 BBB All rights reserved.