开发者

Extract properties from the image file

开发者 https://www.devze.com 2023-03-04 20:53 出处:网络
Is there any way to extract the properties of the image file from vb 6.0? I want to browse the 开发者_Go百科particular photo and then extract the properties like the following from any image format.

Is there any way to extract the properties of the image file from vb 6.0? I want to browse the 开发者_Go百科particular photo and then extract the properties like the following from any image format.

Extract properties from the image file


If you install WIA 2.0 (requires XP SP1, preinstalled in Vista and Windows 7) you can do this:

Private Sub Command1_Click()
    Dim imfSubject As WIA.ImageFile
    Dim vecProperty As WIA.Vector
    Dim propEach As WIA.Property

    With CommonDialog1
        .CancelError = True
        .DialogTitle = "Select JPEG Image"
        .Filter = "JPEG Image (*.jpg, *.jpeg)|*.jpg;*.jpeg|" _
                & "GIF Image (*.gif)|*.gif|" _
                & "PNG Image (*.png)|*.png"
        .FilterIndex = 1
        .Flags = cdlOFNExplorer _
              Or cdlOFNFileMustExist _
              Or cdlOFNLongNames _
              Or cdlOFNPathMustExist _
              Or cdlOFNShareAware
        .InitDir = strStartDir
        On Error Resume Next
        .ShowOpen
        If Err.Number = cdlCancel Then Exit Sub
        On Error GoTo 0

        Log "Photo " & .FileName, ClearLog:=True
        Log
    End With

    Set imfSubject = New WIA.ImageFile
    With imfSubject
        On Error Resume Next
        .LoadFile (CommonDialog1.FileName)
        If Err.Number <> 0 Then
            Log "Error &H" & Hex$(Err.Number) & " (" & CStr(Err.Number) & ") in " _
              & Err.Source
            Log Err.Description
            Err.Clear
            Exit Sub
        End If

        Log "Width = " & .Width
        Log "Height = " & .Height
        Log "Depth = " & .PixelDepth
        Log "HorizontalResolution = " & .HorizontalResolution
        Log "VerticalResolution = " & .VerticalResolution
        Log "FrameCount = " & .FrameCount

        If .IsIndexedPixelFormat Then
            Log "Pixel data contains palette indexes"
        End If

        If .IsAlphaPixelFormat Then
            Log "Pixel data has alpha information"
        End If

        If .IsExtendedPixelFormat Then
            Log "Pixel data has extended color information (16 bit/channel)"
        End If

        If .IsAnimated Then
            Log "Image is animated"
        End If

        For Each propEach In .Properties
            Select Case propEach.Name
                Case "40091"
                    Set vecProperty = propEach.Value
                    Log "Title = " & vecProperty.String

                Case "40092"
                    Set vecProperty = propEach.Value
                    Log "Comment = " & vecProperty.String

                Case "40093"
                    Set vecProperty = propEach.Value
                    Log "Author = " & vecProperty.String

                Case "40094"
                    Set vecProperty = propEach.Value
                    Log "Keywords = " & vecProperty.String

                Case "40095"
                    Set vecProperty = propEach.Value
                    Log "Subject = " & vecProperty.String

                Case Else
                    Log propEach.Name & " = " & CStr(propEach.Value)
            End Select
        Next
    End With
End Sub

The code assumes strStartDir is a global String set to a starting folder for browsing and that there is a Log sub for logging results). It produces results based on the info in the image file, example:

Photo C:\Users\George\Pictures\Phone\IMAG0005.jpg

Width = 1600
Height = 1200
Depth = 24
HorizontalResolution = 96
VerticalResolution = 96
FrameCount = 1
EquipMake = HTC
EquipModel = VOGU100
XResolution = 72
YResolution = 72
ResolutionUnit = 2
DateTime = 2010:05:17 11:54:38
Artist = Bob Riemersma
ExifDTOrig = 2010:05:17 11:54:38
ExifFlash = 0
ExifPixXDim = 1600
ExifPixYDim = 1200
ExifColorSpace = -1
ExifDTDigitized = 2010:05:17 11:54:38
ThumbnailImageWidth = 160
ThumbnailImageHeight = 120
ThumbnailCompression = 6
JPEGInterFormat = 368

You can also use the Shell object to retrieve Windows values for those Properties dialog values but this can be a crapshoot since different Windows versions put them in different spots in the collection involved.

0

精彩评论

暂无评论...
验证码 换一张
取 消