澄清:
如何在不使用外部 DLL 的情况下编辑和保存图像 EXIF / Metadata / FileInfo?
项目:
我正在构建一个供个人使用的应用程序,用于重命名、重新标记和组织我在个人网站上托管的世界末日数量的图像。由于我多年来一直在收集有趣的图片等,因此文件命名约定没有真正的韵律或理由。因此,Image0001.jpg 需要重命名为描述性文件名,并且需要填写 Metadata 字段。
所需的过程将采用现有的 jpg、gif、png、tiff 或 bmp 并执行以下操作:
- 将图像加载到内存中
- 如果需要,将 bmp 文件转换为 jpgs(主要用于较小的文件大小)
- 将图像标签加载到 ImageData 结构中(见下文)
- 将文件数据加载到 ImageData 结构中(需要时)
- 显示图像和标签供用户编辑(在图片框和多个文本框中)
- 允许编辑字段和重命名文件
- 将更改写入图像文件
- 转到下一个文件。
例子:
- 加载 Image0001.jpg。填充 ImageData Structure 字段。
- 输入描述:“lolcat 天花板猫送儿子”。
- ImageData.FileName 更改为“lolcat-ceiling-cat-sends-son.jpg”。
- ImageData.Name、.Keywords、.Title、.Subject 和 .Comments 更改为“lolcat 天花板猫送儿子”。
- 使用新文件名保存文件并保存所有新标签字段。
(稍后,我还将使用 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