3

澄清:

如何在不使用外部 DLL 的情况下编辑和保存图像 EXIF / Metadata / FileInfo?

项目:

我正在构建一个供个人使用的应用程序,用于重命名、重新标记和组织我在个人网站上托管的世界末日数量的图像。由于我多年来一直在收集有趣的图片等,因此文件命名约定没有真正的韵律或理由。因此,Image0001.jpg 需要重命名为描述性文件名,并且需要填写 Metadata 字段。

所需的过程将采用现有的 jpg、gif、png、tiff 或 bmp 并执行以下操作:

  1. 将图像加载到内存中
  2. 如果需要,将 bmp 文件转换为 jpgs(主要用于较小的文件大小)
  3. 将图像标签加载到 ImageData 结构中(见下文)
  4. 将文件数据加载到 ImageData 结构中(需要时)
  5. 显示图像和标签供用户编辑(在图片框和多个文本框中)
  6. 允许编辑字段和重命名文件
  7. 将更改写入图像文件
  8. 转到下一个文件。

例子:

  1. 加载 Image0001.jpg。填充 ImageData Structure 字段。
  2. 输入描述:“lolcat 天花板猫送儿子”。
  3. ImageData.FileName 更改为“lolcat-ceiling-cat-sends-son.jpg”。
  4. ImageData.Name、.Keywords、.Title、.Subject 和 .Comments 更改为“lolcat 天花板猫送儿子”。
  5. 使用新文件名保存文件并保存所有新标签字段。

(稍后,我还将使用 SQL 构建一个参考数据库,其中包含指向这些文件的在线副本的链接,以允许按关键字、主题、文件名等进行搜索,但这是比这一层容易得多的另一层。至少我。)

问题:

到目前为止,几天的研究几乎没有取得可衡量的进展。信息显然被莫名其妙地隐藏在一堆我没有用于搜索的意外搜索关键字后面。任何帮助,将不胜感激。

当前代码原样:

Imports System.IO
Imports System.IO.Path
Imports System.Drawing.Imaging
Imports ImageData '(The Custom Structure below)'
'*Also has a project level reference to the dso.dll referenced below.'

Public Structure ImageData
        Shared FileAuthorAuthor As String
        Shared FileAuthorCategory As String
        Shared FileAuthorComments As String
        Shared FileAuthorCompany As String
        Shared FileAuthorDateCreated As DateTime
        Shared FileAuthorDescription As String
        Shared FileAuthorHeight As Decimal
        Shared FileAuthorHeightResolution As Decimal
        Shared FileAuthorImage As Image
        Shared FileAuthorKeywords As String
        Shared FileAuthorName As String
        Shared FileAuthorPath As String 'URL or IRL'
        Shared FileAuthorRead As Boolean
        Shared FileAuthorSubject As String
        Shared FileAuthorTitle As String
        Shared FileAuthorType As String
        Shared FileAuthorWidth As Decimal
        Shared FileAuthorWidthResolution As Decimal
End Structure 'ImageData

目前查找数据的方法是:

Shared Function ReadExistingData(ByRef FileWithPath As String) As Boolean

        'Extract the FileName'
        Dim PathParts As String() = FileWithPath.Split("\") '"
        Dim FileName As String = PathParts(PathParts.Length - 1) 
        Dim FileParts As String() = FileName.Split(".")
        Dim FileType As String = FileParts(FileParts.Length - 1)

        'Create an Image object. '
        Dim SelectedImage As Bitmap = New Bitmap(FileWithPath)

        'Get the File Info from the Image.'
        Dim ImageFileInfo As New FileInfo(FileWithPath)
        Dim dso As DSOFile.OleDocumentProperties
        dso = New DSOFile.OleDocumentProperties
        dso.Open(FileWithPath.Trim, True, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess)

        ImageData.FileAuthor = dso.SummaryProperties.Author '* Requires dso.DLL'
        ImageData.FileCategory = dso.SummaryProperties.Category '* Requires dso.DLL'
        ImageData.FileComments = dso.SummaryProperties.Comments '* Requires dso.DLL'
        ImageData.FileCompany = dso.SummaryProperties.Company '* Requires dso.DLL'
        ImageData.FileDateCreated = ImageFileInfo.CreationTime
        ImageData.FileDescription = dso.SummaryProperties.Comments  '* Requires dso.DLL.'
        ImageData.FileHeight = SelectedImage.Height
        ImageData.FileHeightResolution = SelectedImage.VerticalResolution
        ImageData.FileImage = New Bitmap(FileWithPath)
        ImageData.FileKeywords = dso.SummaryProperties.Keywords '* Requires dso.DLL'
        ImageData.FileName = FileName
        ImageData.FilePath = FileWithPath
        ImageData.FileRead = ImageFileInfo.IsReadOnly
        ImageData.FileSubject = dso.SummaryProperties.Subject '* Requires dso.DLL'
        ImageData.FileTitle = dso.SummaryProperties.Title '* Requires dso.DLL'
        ImageData.FileType = FileType
        ImageData.FileWidth = SelectedImage.Width
        ImageData.FileWidthResolution = SelectedImage.HorizontalResolution

        Return True

End Function 'ReadExistingData'

只是我审查过的几个“Top Box”搜索结果:

  • dso.DLL:非常有用,但不可取。需要外部 DLL。
    [http://]www.developerfusion.com/code/5093/retrieving-the-summary-properties-of-a-file/

  • 数据不完整 ~ 不回答我的问题
    [http://]msdn.microsoft.com/en-us/library/xddt0dz7.aspx

  • 需要外部 DLL
    [http://]www.codeproject.com/KB/GDI-plus/ImageInfo.aspx

  • 需要外部软件
    [http://]stackoverflow.com/questions/3313474/write-metadata-to-png-image-in-net

  • 旧数据 ~ Visual Studio 2005 和 .NET 2.0
    [http://]www.codeproject.com/KB/graphics/MetaDataAccess.aspx

  • 转换为 BMP:看起来很有用
    [http://]www.freevbcode.com/ShowCode.Asp?ID=5799

4

2 回答 2

1

编辑:这不是 dll 库,您只需将源代码复制到您的项目并创建对象的新实例。

我使用了一个名为 ExifWorks 的类,在这里找到:http: //www.codeproject.com/KB/vb/exif_reader.aspx? msg=1813077 它的用法很简单,

Dim EX As New ExifWorks(bitmap)
Dim dateStr As String = EX.DateTimeOriginal
Dim description As String = EX.Description
EX.SetPropertyString(ExifWorks.TagNames.ImageDescription, "my description")

这是迄今为止我发现的最简单的方法。如果您遇到任何问题,请告诉我。

于 2011-01-04T20:04:08.663 回答
0
    Dim MyValue As String = ""

    For Each item In PictureBox1.Image.PropertyIdList
        MyValue = System.Text.Encoding.UTF8.GetString(PictureBox1.Image.GetPropertyItem(item).Value)
        ListBox1.Items.Add(MyValue)
    Next
于 2017-07-21T19:56:51.660 回答