'VB 通过二进制方式来判断图片的格式,下面只对 JPG 、GIF、PNG、BMP、ICO 几个常用的图片格式做了判断。
Public Function GetImageType(ByteArray() As Byte) As String
If ByteArray(0) = &HFF And ByteArray(1) = &HD8 Then
GetImageType = "JPG"
ElseIf ByteArray(0) = &H47 And ByteArray(1) = &H49 Then
GetImageType = "GIF"
ElseIf ByteArray(0) = &H42 And ByteArray(1) = &H4D Then
GetImageType = "BMP"
ElseIf ByteArray(0) = &H89 And ByteArray(1) = &H50 Then
GetImageType = "PNG"
ElseIf ByteArray(0) = &H0 And ByteArray(1) = &H0 And ByteArray(2) = &H1 And ByteArray(3) = &H0 And ByteArray(4) = &H1 Then
GetImageType = "ICO"
End If
End Function
评论