« VB 设置ListView中指定一行的背景颜色增强版VB正则表达式(VBScript.RegExp)组件,兼容Perl正则语法 »

VB 判断图片文件的类型格式

VB 通过二进制方式来判断图片的格式,下面只对 JPG 、GIF、PNG、BMP、ICO 几个常用的图片格式做了判断。
VBScript code复制代码
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

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Copyright © 2009-2011 linhaibo.com. All Rights Reserved .