gpt4 book ai didi

image - 从图像文件中提取属性

转载 作者:行者123 更新时间:2023-12-02 01:20:07 35 4
gpt4 key购买 nike

有没有办法从vb 6.0中提取图像文件的属性?我想浏览特定的照片,然后从任何图像格式中提取如下属性。

enter image description here

最佳答案

如果您安装WIA 2.0 (需要 XP SP1,预装在 Vista 和 Windows 7 中)您可以执行以下操作:

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

代码假设 strStartDir 是一个全局字符串,设置为用于浏览的起始文件夹,并且有一个用于记录结果的 Log 子项。它根据图像文件中的信息生成结果,例如:

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

您还可以使用 Shell 对象来检索这些“属性”对话框值的 Windows 值,但这可能会很麻烦,因为不同的 Windows 版本将它们放在所涉及的集合中的不同位置。

关于image - 从图像文件中提取属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5927828/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com