Results 1 to 6 of 6

Thread: Jpeg header info[resolved]

Threaded View

  1. #1

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172

    Jpeg header info[resolved]

    Hi can anybody tell me how to get Jpeg header data added by a digital video camera?

    i really only need the Photo taken on property

    below is 3 posts of code i found for vb6 but cant seem to make it work in .net
    VB Code:
    1. '------------------------------------------------------------------------------------------------------------
    2. '- EXIF Meta Tag reader
    3. '- author: Chavdar Jordanov
    4. '- based on the Exif format description at [url]http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html[/url]
    5. '------------------------------------------------------------------------------------------------------------
    6. Option Explicit
    7.  
    8. Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    9.  
    10. Private Type tIDF 'main structure, containg tag parameters
    11.     ID As Long
    12.     Name As String
    13.     Format As Long
    14.     Length As Long
    15.     Data As Variant
    16.     StringData As String
    17. End Type
    18.  
    19. Public Enum enTAG 'enumerator containing the most common metatag names and their respective IDs
    20.     ImageDescription = 270
    21.     Make = 271
    22.     Model = 272
    23.     Orientation = 274
    24.     XResolution = 282
    25.     YResolution = 283
    26.     ResolutionUnit = 296
    27.     Software = 305
    28.     DateTime = 306
    29.     WhitePoint = 318
    30.     PrimaryChromaticities = 319
    31.     YCbCrCoefficients = 529
    32.     YCbCrPositioning = 531
    33.     ReferenceBlackWhite = 532
    34.     Copyright = 33432
    35.     ExifOffset = 34665
    36.     Exposuretime = 33434
    37.     FNumber = 33437
    38.     ExposureProgram = 34850
    39.     ISOSpeedRatings = 34855
    40.     ExifVersion = 36864
    41.     DateTimeOriginal = 36867
    42.     DateTimeDigitized = 36868
    43.     ComponentsConfiguration = 37121
    44.     CompressedBitsPerPixel = 37122
    45.     ShutterSpeedValue = 37377
    46.     ApertureValue = 37378
    47.     BrightnessValue = 37379
    48.     ExposureBiasValue = 37380
    49.     MaxApertureValue = 37381
    50.     SubjectDistance = 37382
    51.     MeteringMode = 37383
    52.     LightSource = 37384
    53.     Flash = 37385
    54.     FocalLength = 37386
    55.     MakerNote = 37500
    56.     UserComment = 37510
    57.     SubsecTime = 37520
    58.     SubsecTimeOriginal = 37521
    59.     SubsecTimeDigitized = 37522
    60.     FlashPixVersion = 40960
    61.     ColorSpace = 40961
    62.     ExifImageWidth = 40962
    63.     ExifImageHeight = 40963
    64.     RelatedSoundFile = 40964
    65.     ExifInteroperabilityOffset = 40965
    66.     FocalPlaneXResolution = 41486
    67.     FocalPlaneYResolution = 41487
    68.     FocalPlaneResolutionUnit = 41488
    69.     ExposureIndex = 41493
    70.     SensingMethod = 41495
    71.     FileSource = 41728
    72.     SceneType = 41729
    73.     CFAPattern = 41730
    74. End Enum
    75.  
    76. Private Enum enFormat
    77.     unsignedByte = 1
    78.     asciiString = 2
    79.     unsignedShort = 3
    80.     unsignedLong = 4
    81.     unsignedRationale = 5
    82.     signedByte = 6
    83.     undefined = 7
    84.     signedShort = 8
    85.     signedLong = 9
    86.     signedRationale = 10
    87.     singleFloat = 11
    88.     doubleFloat = 12
    89. End Enum
    90.  
    91. Private m_ImageFile As String 'path to the file on the disk
    92. Private m_Intel As Boolean    'flag containing the byte alignment of the record
    93. Private m_IniFile As String   'path to the exif.ini file containing description of the codes
    94.  
    95. Private DataLen 'array containing the byte length of each data format
    96. Private IDName  'array containing tag names
    97. Private IDNo    'array containing tag IDs
    98. Private bParsed As Byte 'flag that the file has been parsed succesfuly
    99. Private IFD() As tIDF 'array containing all metatags
    100. '======== Interface part ==========
    101.  
    102. '-- file containing the jpeg image --
    103. Public Property Get ImageFile() As Variant
    104.     ImageFile = m_ImageFile
    105. End Property
    106.  
    107. Public Property Let ImageFile(ByVal vNewValue As Variant)
    108.     m_ImageFile = vNewValue
    109.     bParsed = ReadMetaInfo(m_ImageFile)
    110. End Property
    111.  
    112. '-- returns the byte alignment order for the file --
    113. Public Property Get IntelByteAlignment() As Boolean
    114.     IntelByteAlignment = m_Intel
    115. End Property
    116.  
    117. '-- method, which returns the numeric and string values for a single metatag ---
    118. Public Function MetaInfo(ByVal l_ID As enTAG, ByRef StringData As String) As Long
    119.     Dim i As Integer
    120.     If bParsed = 0 Then
    121.         For i = 1 To UBound(IFD)
    122.             If IFD(i).ID = l_ID Then
    123.                 StringData = IFD(i).StringData
    124.                 MetaInfo = IFD(i).Data
    125.                 Exit Function
    126.             End If
    127.         Next i
    128.         StringData = "Tag " + CStr(l_ID) + " not found."
    129.     ElseIf bParsed = 1 Then
    130.         Err.Raise 10, "MetaInfo", "File is not in EXIF format."
    131.     ElseIf bParsed = 2 Then
    132.         Err.Raise 11, "MetaInfo", "Error parsing the file."
    133.     End If
    134. End Function
    135.  
    136. '-- returns Exif tag name based on its ID --
    137. Function GetTagName(ByVal lID As enTAG) As String
    138.     Dim i As Integer
    139.     For i = 0 To UBound(IDNo)
    140.         If lID = IDNo(i) Then
    141.             GetTagName = IDName(i)
    142.             Exit Function
    143.         End If
    144.     Next
    145.     'tag name unknown; return tag ID
    146.     GetTagName = "Tag #" + CStr(lID)
    147. End Function
    148.  
    149. '--- Lists all metatags found in the header ---
    150. Function ListInfo() As String
    151.     Dim i As Integer
    152.     If bParsed = 0 Then
    153.         For i = 1 To UBound(IFD)
    154.             ListInfo = ListInfo + IFD(i).Name + ": " + IFD(i).StringData + vbCrLf
    155.         Next i
    156.     ElseIf bParsed = 1 Then
    157.         ListInfo = "File is not in EXIF format."
    158.     ElseIf bParsed = 2 Then
    159.         ListInfo = "Could not open the file."
    160.     End If
    161. End Function
    162.  
    163. '========= PARSING FUNCTIONS ==========
    164.  
    165. '-- parses the jpeg header and extracts all Exif information from it --
    166. Private Function ReadMetaInfo(sFileName As String) As Integer
    167.     Dim sJPEG_Header As String, B() As Byte
    168.     Dim lPos As Long, Offset As Long, HeaderStart As Long
    169.     Dim i As Integer
    170.     Dim NoOfRecs As Integer
    171.     On Error GoTo ErrRead
    172.     sJPEG_Header = ReadFile(sFileName, 4096) 'may be changed to reflect the actual header size
    173.     If sJPEG_Header = "" Then
    174.         Err.Raise 2, "ReadMetaInfo", "File not found."
    175.     Else
    176.         HeaderStart = InStr(1, sJPEG_Header, "Exif" + Chr(0), vbBinaryCompare) 'start of EXIF header
    177.         If HeaderStart = 0 Then ReadMetaInfo = 1: Exit Function
    178.         HeaderStart = HeaderStart + 6 'start of data
    179.         lPos = HeaderStart
    180.         m_Intel = Mid(sJPEG_Header, lPos, 2) = "II" 'byte alignment
    181.         lPos = lPos + 4
    182.         Offset = BVal(sJPEG_Header, lPos, 4, m_Intel) 'offset to the first IFD
    183.         ReDim IFD(0)
    184.         'parse the main IFD directory and get the offset to the IFDSubDir
    185.         Offset = ParseIDF(sJPEG_Header, HeaderStart, Offset, ExifOffset)
    186.         Offset = ParseIDF(sJPEG_Header, HeaderStart, Offset, ExifInteroperabilityOffset)
    187.     End If
    188. ExitRead:
    189.     Exit Function
    190. ErrRead:
    191.     Dim S
    192.     S = Err.Description
    193.     Err.Raise 1, "ReadMetaInfo", S
    194.     ReadMetaInfo = 2
    195. End Function


    any help is great :d
    Last edited by Ultimasnake; Dec 3rd, 2003 at 09:27 AM.
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width