VB.NET重命名文件和重新标记/编辑图像元数据/元标记 [英] VB.NET Renaming File and Retagging / Edit Image MetaData / Meta Tags
问题描述
项目:
我正在建立个人使用的应用重新命名,重新编辑和组织我个人网站上托管的图像的启示数量。由于我一直在收集有趣的图片等几年,文件命名约定没有真正的韵律或理由。 Ergo,Image0001.jpg需要重新命名为描述性文件名,并且需要填写元数据字段。
所需的过程将采用现有的jpg ,gif,png,tiff或bmp,然后执行以下操作:
- 将图像加载到内存中b
- 如果需要,将bmp文件转换为jpgs(大多数文件较小)
- 将图像标签载入ImageData结构(见下文)
- 将文件数据加载到ImageData结构中(需要的地方)
- 显示用户要编辑的图像和标签(在图片框和多个文本框中)
- 允许编辑字段并对文件进行重命名
- 将更改写入映像文件
- 转至下一个文件
- 加载Image0001.jpg。填充ImageData结构字段。
- 输入描述:lolcat ceiling cat sent son。
- ImageData.FileName更改为lolcat-ceiling-cat -sends-son.jpg。
- ImageData.Name,.Keywords,.Title,.Subject和.Comments更改为lolcat ceiling cat sent son。
- 保存具有新文件名的文件并保存所有新的标记字段。
$ b $(稍后我还将使用SQL建立一个指向数据库的链接到这些文件的在线副本,以允许通过关键字,主题,文件名等进行搜索,但这是另一个层比这更容易。至少对我来说)。
$ b问题:
到目前为止,几天的研究几乎没有取得可测量的进展。信息显然已经被一些意想不到的搜索关键词所掩盖,这些关键词我还没有用于搜索。任何帮助将不胜感激。
当前代码是:
Imports System.IO
导入System.IO.Path
导入System.Drawing.Imaging
导入ImageData'(下面的自定义结构)'
' *
公共结构ImageData
共享FileAuthorAuthor作为字符串
共享FileAuthorCategory作为字符串
共享FileAuthorComments作为字符串
共享FileAuthorCompany作为字符串
共享FileAuthorDateCreated作为DateTime
共享FileAuthorDescription作为字符串
共享FileAuthorHeight作为十进制
共享FileAuthorHeightResolution作为十进制
共享FileAuthorImage作为图像
共享FileAuthorKeywords作为字符串
共享FileAuthorName作为字符串
共享FileAuthorPath作为字符串'URL或IRL'
共享Fil eAuthorRead As布尔
共享FileAuthorSubject作为字符串
共享FileAuthorTitle作为字符串
共享FileAuthorType作为字符串
共享FileAuthorWidth作为十进制
共享FileAuthorWidthResolution作为十进制
End Structure' ImageData
目前找到资料的方法是:
共享函数ReadExistingData(ByRef FileWithPath As String)As Boolean
提取文件名'
Dim PathParts As String()= FileWithPath ())
Dim FileName As String = PathParts(PathParts.Length - 1)
Dim FileParts As String()= FileName.Split(。)
Dim FileType As String = FileParts(FileParts.Length - 1)
'创建一个Image对象。 '
Dim SelectedImage As Bitmap = New Bitmap(FileWithPath)
'从图像获取文件信息'
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'*需要dso.DLL'
ImageData.FileCategory = dso.SummaryProperties.Category'*需要dso.DLL'
ImageData.FileComments = dso.SummaryProperties.Comments'*需要dso.DLL'
ImageData.FileCompany = dso.SummaryProperties.Company'*需要dso.DLL'
ImageData.FileDateCreated = ImageFileInfo.CreationTime
ImageData.FileDescription = dso.SummaryProperties.Comments'*需要dso.DLL。 '
ImageData.FileHeight = SelectedIm age.Height
ImageData.FileHeightResolution = SelectedImage.VerticalResolution
ImageData.FileImage =新位图(FileWithPath)
ImageData.FileKeywords = dso.SummaryProperties.Keywords'*需要dso.DLL'
ImageData.FileName = FileName
ImageData.FilePath = FileWithPath
ImageData.FileRead = ImageFileInfo.IsReadOnly
ImageData.FileSubject = dso.SummaryProperties.Subject'*需要dso.DLL'
ImageData.FileTitle = dso.SummaryProperties.Title'*需要dso.DLL'
ImageData.FileType = FileType
ImageData.FileWidth = SelectedImage.Width
ImageData.FileWidthResolution = SelectedImage.HorizontalResolution
返回True
End Function'ReadExistingData'
<
-
dso。 DLL:非常有帮助,b不希望的。需要外部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:看起来有用 -
- load image into memory
- convert bmp files to jpgs if needed (for a smaller file size, mostly)
- load image tags into ImageData Structure (see below)
- load file data into ImageData Structure (where needed)
- display image and tags for user to edit (In a Picture Box and several Text Boxes)
- allow editing of fields and renaming of the file
- write the changes to the image file
- go to next file.
- Load Image0001.jpg. Populate ImageData Structure fields.
- Type in Description: "lolcat ceiling cat sends son".
- ImageData.FileName changed to "lolcat-ceiling-cat-sends-son.jpg".
- ImageData.Name, .Keywords, .Title, .Subject, and .Comments changed to "lolcat ceiling cat sends son".
- Save file with new filename and save all new tag fields.
The dso.DLL: Very Helpful, but undesirable. Requires external DLL.
[http://]www.developerfusion.com/code/5093/retrieving-the-summary-properties-of-a-file/Incomplete Data ~ Does not answer my questions
[http://]msdn.microsoft.com/en-us/library/xddt0dz7.aspxRequires external DLL
[http://]www.codeproject.com/KB/GDI-plus/ImageInfo.aspxExternal Software required
[http://]stackoverflow.com/questions/3313474/write-metadata-to-png-image-in-netOld Data ~ Visual Studio 2005 and .NET 2.0
[http://]www.codeproject.com/KB/graphics/MetaDataAccess.aspxConvert to BMP: Looks useful
[http://]www.freevbcode.com/ShowCode.Asp?ID=5799
示例:
[http://] www.freevbcode.com/ShowCode.Asp?编辑:这不是一个dll库,编号为5799 您只需将源代码复制到您的项目中,并创建一个新的对象实例。
我使用一个名为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)
这是迄今为止我找到的最简单的方法。如果遇到任何问题,请告诉我。
Clarifiration:
How do I Edit and Save Image EXIF / Metadata / FileInfo without using an external DLL?
Project:
I'm building an app for personal use to rename, retag, and organize the apocalyptic quantity of images I host on my personal website. As I have been collecting funny pictures and such for several years, there is no real rhyme or reason to the file naming conventions. Ergo, Image0001.jpg needs to be renamed to a descriptive filename, and the Metadata fields need to be filled in.
The desired process will take an existing jpg, gif, png, tiff or bmp and do the following:
Example:
(Later, I will also be using SQL to build a referential database with links to the online copies of these files to allow for searching by keywords, subject, filename, etc, but that's another layer that's much easier than this one. At least to me.)
Problem:
So far, several days of research have yielded almost no measurable progress. Information has apparently been inexplicably hidden behind a bunch of unexpected search keywords that I have not though to use for my searches. Any help would be appreciated.
Current Code as is:
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
And the current method for finding the data is:
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'
Just a couple of the "Top Box" search hits I've reviewed:
EDIT: This isn't a dll library, you just copy the source code to your project and create a new instance of the object.
I use a class called ExifWorks, found here: http://www.codeproject.com/KB/vb/exif_reader.aspx?msg=1813077 It's usage is simple,
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")
This is the easiest way I've found so far. Let me know if you run into any problems.
这篇关于VB.NET重命名文件和重新标记/编辑图像元数据/元标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!