用JPEG文件EXIF信息ASP版本(4)
发表于:2007-06-30来源:作者:点击数:
标签:
Function OpenJPGFile(FileName) Dim Ascii, lastHex, currentHex, SOSFound Dim FSO, File, i If Not FileName = Then If InStr(1, FileName, :) = 0 Then FileName = Server.MapPath(FileName) End If Set FSO = Server.CreateObject(Scripting.FileSystemO
Function OpenJPGFile(FileName)
Dim Ascii, lastHex, currentHex, SOSFound
Dim FSO, File, i
If Not FileName = "" Then
If InStr(1, FileName, ":") = 0 Then
FileName = Server.MapPath(FileName)
End If
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(FileName) Then
Set File = FSO.OpenTextFile(FileName, ForReading, False, TristateFalse)
i = 0
While Not File.AtEndOfStream and SOSFound = false
Ascii = Asc(File.Read(1))
lastHex = currentHex
currentHex = Right("0" & Hex(Ascii), 2)
if lastHex & currentHex = "FFDA" or i > 100000 then
SOSFound = true
end if
ExifTemp(i) = currentHex
i = i + 1
ReDim Preserve ExifTemp(i)
Wend
File.Close
Set File = Nothing
Else
Response.Write("File does not exist")
End If
Set FSO = Nothing
End If
end function
Sub GetDirectoryEntries(Offset)
Dim No_of_Entries
Dim Upper_IFDDirectory
Dim NewDimensions
Dim Processed_ExifSubIFD
Dim BytesPerComponent
Dim Offset_to_MakerNote
Dim i, j, k
Do
If IsIntel Then
No_of_Entries = _
HexToDec(ExifTemp(Offset + 1)) * 256 + _
HexToDec(ExifTemp(Offset + 0))
Else
No_of_Entries = _
HexToDec(ExifTemp(Offset + 0)) * 256 + _
HexToDec(ExifTemp(Offset + 1))
End If
On Error Resume Next
Upper_IFDDirectory = UBound(IFDDirectory)
On Error GoTo 0
NewDimensions = Upper_IFDDirectory + No_of_Entries
ReDim Preserve IFDDirectory(NewDimensions)
For i = 1 To No_of_Entries
k = Upper_IFDDirectory + i - 1
IFDDirectory(k) = array(null,null,null,null,null,null,null)
‘’With IFDDirectory(Upper_IFDDirectory + i)
If IsIntel Then
IFDDirectory(k)(IFD_IDX_Tag_No) = _
ExifTemp((Offset + 2) + ((i - 1) * 12) + 1) & _
ExifTemp((Offset + 2) + ((i - 1) * 12) + 0)
‘’HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 1)) * 256 + _
‘’HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 0))
IFDDirectory(k)(IFD_IDX_Data_Format) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 3)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 2))
IFDDirectory(k)(IFD_IDX_Components) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 7)) * 256 * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 6)) * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 5)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 4))
Select Case IFDDirectory(k)(IFD_IDX_Data_Format)
Case m_BYTE, m_SBYTE
BytesPerComponent = 1
If IFDDirectory(k)(IFD_IDX_Components) * BytesPerComponent <= 4 Then
IFDDirectory(k)(IFD_IDX_Value) = _
ExifTemp((Offset + 2) + ((i - 1) * 12) + 11) & _
ExifTemp((Offset + 2) + ((i - 1) * 12) + 10) & _
ExifTemp((Offset + 2) + ((i - 1) * 12) + 9) & _
ExifTemp((Offset + 2) + ((i - 1) * 12) + 8)
Else
IFDDirectory(k)(IFD_IDX_OffsetToValue) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 11)) * 256 * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10)) * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8))
For j = 0 To IFDDirectory(k)(IFD_IDX_Components) - 1
IFDDirectory(k)(IFD_IDX_Value) = IFDDirectory(k)(IFD_IDX_Value) & ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + j)
Next
End If
Case m_STRING, m_UNDEFINED
BytesPerComponent = 1
If IFDDirectory(k)(IFD_IDX_Components) * BytesPerComponent <= 4 Then
IFDDirectory(k)(IFD_IDX_Value) = _
Chr(HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 11))) & _
Chr(HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10))) & _
Chr(HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9))) & _
Chr(HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8)))
Else
IFDDirectory(k)(IFD_IDX_OffsetToValue) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 11)) * 256 * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10)) * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8))
For j = 0 To IFDDirectory(k)(IFD_IDX_Components) - 2
IFDDirectory(k)(IFD_IDX_Value) = IFDDirectory(k)(IFD_IDX_Value) & Chr(HexToDec(ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + j)))
Next
End If
Case m_SHORT, m_SSHORT
BytesPerComponent = 2
If IFDDirectory(k)(IFD_IDX_Components) * BytesPerComponent <= 4 Then
IFDDirectory(k)(IFD_IDX_Value) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 11)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10)) + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8))
Else
IFDDirectory(k)(IFD_IDX_OffsetToValue) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 11)) * 256 * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10)) * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8))
For j = 0 To IFDDirectory(k)(IFD_IDX_Components) - 1
IFDDirectory(k)(IFD_IDX_Value) = IFDDirectory(k)(IFD_IDX_Value) & ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + j)
Next
End If
Case m_LONG, m_SLONG
BytesPerComponent = 4
If IFDDirectory(k)(IFD_IDX_Components) * BytesPerComponent <= 4 Then
IFDDirectory(k)(IFD_IDX_Value) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 11)) * 256 * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10)) * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8))
Else
IFDDirectory(k)(IFD_IDX_OffsetToValue) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 11)) * 256 * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10)) * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8))
For j = 0 To IFDDirectory(k)(IFD_IDX_Components) - 1
IFDDirectory(k)(IFD_IDX_Value) = IFDDirectory(k)(IFD_IDX_Value) & ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + j)
Next
End If
Case m_RATIONAL, m_SRATIONAL
BytesPerComponent = 8
IFDDirectory(k)(IFD_IDX_OffsetToValue) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 11)) * 256 * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10)) * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8))
IFDDirectory(k)(IFD_IDX_Value) = _
HexToDec(ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + 3)) * 256 * 256 * 256 + _
HexToDec(ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + 2)) * 256 * 256 + _
HexToDec(ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + 1)) * 256 + _
HexToDec(ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + 0)) & _
"/" & _
HexToDec(ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + 7)) * 256 * 256 * 256 + _
HexToDec(ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + 6)) * 256 * 256 + _
HexToDec(ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + 5)) * 256 + _
HexToDec(ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + 4))
End Select
Else
IFDDirectory(k)(IFD_IDX_Tag_No) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 0)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 1))
IFDDirectory(k)(IFD_IDX_Data_Format) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 2)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 3))
IFDDirectory(k)(IFD_IDX_Components) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 4)) * 256 * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 5)) * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 6)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 7))
Select Case IFDDirectory(k)(IFD_IDX_Data_Format)
Case m_BYTE, m_SBYTE
BytesPerComponent = 1
If IFDDirectory(k)(IFD_IDX_Components) * BytesPerComponent <= 4 Then
IFDDirectory(k)(IFD_IDX_Value) = _
ExifTemp((Offset + 2) + ((i - 1) * 12) + 8) & _
ExifTemp((Offset + 2) + ((i - 1) * 12) + 9) & _
ExifTemp((Offset + 2) + ((i - 1) * 12) + 10) & _
ExifTemp((Offset + 2) + ((i - 1) * 12) + 11)
Else
IFDDirectory(k)(IFD_IDX_OffsetToValue) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8)) * 256 * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9)) * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10)) * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 11))
For j = 0 To IFDDirectory(k)(IFD_IDX_Components) - 1
IFDDirectory(k)(IFD_IDX_Value) = IFDDirectory(k)(IFD_IDX_Value) & ExifTemp(Offset_to_TIFF + IFDDirectory(k)(IFD_IDX_OffsetToValue) + j)
Next
End If
Case m_STRING, m_UNDEFINED
BytesPerComponent = 1
If IFDDirectory(k)(IFD_IDX_Components) * BytesPerComponent <= 4 Then
IFDDirectory(k)(IFD_IDX_Value) = _
Chr(HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8))) & _
Chr(HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9))) & _
Chr(HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10))) & _
Chr(HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 11)))
Else
IFDDirectory(k)(IFD_IDX_OffsetToValue) = _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 8)) * 256 * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 9)) * 256 * 256 + _
HexToDec(ExifTemp((Offset + 2) + ((i - 1) * 12) + 10)) * 256 + _
原文转自:http://www.ltesting.net