澄清:
如何在不使用外部 DLL 的情况下编辑和保存图像 EXIF/元数据/文件信息?
Project:
我正在构建一个供个人使用的应用程序,用于重命名、重新标记和组织我在个人网站上托管的大量图像。由于我多年来一直在收集有趣的图片等,因此文件命名约定没有真正的韵律或理由。因此,Image0001.jpg 需要重命名为描述性文件名,并且需要填写元数据字段。
所需的过程将采用现有的 jpg、gif、png、tiff 或 bmp 并执行以下操作:
- 将图像加载到内存中
- 如果需要,将 bmp 文件转换为 jpg(主要是为了较小的文件大小)
- 将图像标签加载到 ImageData 结构中(见下文)
- 将文件数据加载到 ImageData 结构中(需要时)
- 显示图像和标签供用户编辑(在图片框和多个文本框中)
- 允许编辑字段和重命名文件
- 将更改写入图像文件
- 转到下一个文件。
例子:
- 加载 Image0001.jpg。填充 ImageData 结构字段。
- 输入描述:“lolcat 天花板猫发送儿子”。
- ImageData.FileName 更改为“lolcat-ceiling-cat-sends-son.jpg”。
- ImageData.Name、.Keywords、.Title、.Subject 和 .Comments 更改为“lolcat 天花板猫发送儿子”。
- 使用新文件名保存文件并保存所有新标签字段。
(稍后,我还将使用 SQL 构建一个参考数据库,其中包含这些文件的在线副本的链接,以允许按关键字、主题、文件名等进行搜索,但这是另一层,比这一层容易得多。至少我。)
Problem:
到目前为止,几天的研究几乎没有取得任何可衡量的进展。信息显然莫名其妙地隐藏在一堆意想不到的搜索关键字后面,我并没有想到将这些关键字用于我的搜索。任何帮助,将不胜感激。
当前代码如下:
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'
我回顾过的几个“顶盒”搜索结果:
dso.DLL:非常有帮助,但不可取。需要外部 DLL。
[http://]www.developerfusion.com/code/5093/retriving-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
编辑:这不是 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")
这是迄今为止我发现的最简单的方法。如果您遇到任何问题,请告诉我。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)