VB.NET 重命名文件和重新标记/编辑图像元数据/元标记

2023-12-11

澄清:

如何在不使用外部 DLL 的情况下编辑和保存图像 EXIF/元数据/文件信息?

Project:

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

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

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

例子:

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

(稍后,我还将使用 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(使用前将#替换为@)

VB.NET 重命名文件和重新标记/编辑图像元数据/元标记 的相关文章

  • Javascript 像素操作:这些不是我的颜色

    我知道类似的问题已经被问过好几次了 但我还没有找到我想要的东西 我正在将图像读入画布对象 在 JavaScript 中 并尝试操作一些特定的像素 例如 我正在寻找颜色 RGB 224 64 102 并尝试将其更改为其他颜色 我可以将灰度应用
  • 如何缩放图像的一部分并插入到 matplotlib 中的同一图中

    我想缩放数据 图像的一部分并将其绘制在同一个图中 看起来有点像这个图 是否可以在同一图中插入缩放图像的一部分 我认为可以用子图绘制另一个图形 但它绘制了两个不同的图形 我还阅读了添加补丁以插入矩形 圆形 但不确定将图像的一部分插入到图中是否
  • VB.NET“With”声明——拥抱还是避免?

    在工作中 我经常从事一些项目 其中某些对象的许多属性必须在其构建过程中或在其生命周期的早期进行设置 为了方便和可读性 我经常使用With语句来设置这些属性 我发现 With Me Elements PropertyA True Proper
  • Google Chrome 中不缓存动态加载的图像

    使用 jQuery 加载的图像未保存在 Google Chrome 的缓存中 每次都会从服务器下载 情况 我正在使用 jQuery slimbox2 在 灯箱 中加载图片 此时没有什么特别的 我添加了一些 jQuery 代码来检测鼠标光标何
  • 使用 Angular JS ng-src 的后备(默认)图像

    我正在尝试使用从模式返回的数据设置图像源 这是在 ng repeat 循环内 div div span table tr td class imgContainer img td tr table span div div
  • “更新/取消”按钮不会出现在模板字段编辑按钮中

    当您使用 Gridview 的每一行创建编辑按钮时CommandField单击后它会显示更新 取消按钮 以便您可以接受 取消更改 但是 我想要一个带有工具提示文本的编辑按钮 因为CommandField没有工具提示属性 我用过Templat
  • 文件输出流到文件输入流

    将 FileOutputStream 转换为 FileInputStream 的最简单方法是什么 一段代码就很好 这可能对您有帮助 http ostermiller org convert java outputstream inputst
  • 改变 UIImage 颜色

    我正在尝试更改 UIImage 的颜色 我的代码 UIImage coloredImage UIImage firstImage withColor UIColor color UIGraphicsBeginImageContext fir
  • 不建议在 VB.Net 中使用 Mid()、Instr()、LBound()、UBound() 等吗?

    我有 C 背景 但现在主要使用 VB Net 在我看来 上述函数 以及其他函数 例如 UCase LCase 等是 VB6 及之前版本的遗留物 在 VB Net 中使用这些函数是不受欢迎的 还是纯粹取决于个人喜好 我个人的偏好是远离它们 但
  • 如何判断一个类是否被某个特定属性修饰

    我试图确定接口是否用特定属性装饰 例如我有以下界面
  • UIImage initWithContentsOfFile 不起作用

    我有问题 我想避免 UIImage imageNamed 所以我做了 UIImage prodImg UIImage alloc initWithContentsOfFile myimage png controller productIm
  • 使用 Fortran 90 正确读取输入文件中的注释行

    据我了解 Fortran 在从文件读取数据时 会跳过以星号 开头的行 假设它们是注释 好吧 我似乎在用我创建的一个非常简单的程序实现这种行为时遇到了问题 这是我的简单 Fortran 程序 1 program test 2 3 intege
  • 使用 VB.NET 检查 Word 文档中的字体样式

    我想使用vb net检查一个word文件 并检查文档中的样式是否正确 我必须在word文档中检查这些表达式 a Verdana 16 pt Bold Red b Verdana 12 pt Bold Italic Blue c Verdan
  • VB - 如何读取和写入二进制文件?

    如何从任何文件读取原始字节数组 Dim bytes as Byte 然后将该字节数组写回到新文件中 我需要它作为字节数组来在两者之间进行一些处理 我目前正在使用 To read Dim fInfo As New FileInfo dataP
  • 移动/调整窗口大小时闪烁

    我开发了一个显示 jpeg 图像的应用程序 它可以显示 4 个图像 屏幕的每个象限各一个 为此 它使用了 4 个窗口 窗口没有边框 框架 也没有标题栏 当加载新图像时 窗口大小会根据新图像进行调整 然后显示该图像 尤其是当窗户做得较大时 经
  • 为什么我的图像下方有空间? [复制]

    这个问题在这里已经有答案了 图像在下面获得了神秘的空白空间 即使padding 0 margin 0被应用 示范 http jsfiddle net cLETP 红色边框应该包围图像 但底部有空间 造成这种情况的原因是什么 如何删除该空间
  • 如何在 Microsoft 报告中显示字节数组中的图像

    我使用报表文件和 ReportViewer 控件来显示在运行时从对象动态加载数据的报表 我需要显示一个以字节数组形式存储在对象中的图像 PictureBox 的值当前设置为 First Fields ImageData Value dtst
  • 在android中通过BLE传输图像

    我使用以下代码传输 1 MB 的图像 如果在每个数据包之间实现线程延迟 则图像将成功传输 如果未设置线程延迟 则所有数据包均从BluetoothGattServer 发送 但BluetoothGattCallback 不会接收所有数据包 任
  • Android 相机未保存在特定文件夹 [MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA]

    当我在 Intent 中使用 MediaStore INTENT ACTION STILL IMAGE CAMERA 时遇到问题 相机正常启动 但它不会将文件保存在我的特定文件夹 photo 中 但是当我使用 MediaStore ACTI
  • react-native - 图像需要来自 JSON 的本地路径

    你好社区 我正在react native中开发一个测试应用程序 并尝试从本地存储位置获取图像 我实际在做什么 我将图像直接链接源提供给 var 并在渲染函数中调用此方法 react 0 14 8 react native 0 23 1 np

随机推荐