|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
这个AI代码。。。
Function IsPictureFile(filePath As String) As Boolean
Dim fileNumber As Integer
Dim fileHeader As String
Dim pictureHeaders As Variant
Dim i As Integer
' 文件描述符
fileNumber = FreeFile()
' 打开文件用于二进制读取
Open filePath For Binary As #fileNumber
' 读取前8个字节(通常足够判断文件类型)
fileHeader = Space$(8)
Get #fileNumber, 1, fileHeader
' 关闭文件
Close #fileNumber
' 图片文件头部信息
pictureHeaders = Array( _
"FFD8FFE0", "FFD8FFE1", "FFD8FFE8", "FFD9", "89504E47", _
"47494638", "0A000200", "00000022", "00000018", "49492A00", _
"424D", "4D42", "414331303130313800", "000001BA", "000001B3")
' 判断文件头是否匹配图片文件头部信息
For i = LBound(pictureHeaders) To UBound(pictureHeaders)
If HexToString(Left$(fileHeader, Len(pictureHeaders(i)))) = pictureHeaders(i) Then
IsPictureFile = True
Exit Function
End If
Next i
IsPictureFile = False
End Function
' 将十六进制字符串转换为二进制字符串
Function HexToString(hexStr As String) As String
Dim i As Integer
Dim bStr As String
For i = 1 To Len(hexStr) Step 2
bStr = bStr & Chr$("&H" & Mid$(hexStr, i, 2))
Next i
HexToString = bStr
End Function |
评分
-
3
查看全部评分
-
|