VB.NET File Rename and Drag / Drop Image MetaData / Meta Tags

Clarifiration:

How to edit and save EXIF ​​/ Metadata / FileInfo images without using an external DLL?

Project:

I am creating a personal use application to rename, reassign and organize the apocalyptic number of images that I post on my personal website. As I have been collecting funny photos and such for several years, there is no real rhyme or reason for file naming conventions. Ergo, Image0001.jpg must be renamed to a descriptive file name, and the metadata fields must be filled.

The desired process will take the existing jpg, gif, png, tiff or bmp and do the following:

  • Loading image into memory
  • convert BMP files to jpgs if necessary (for a smaller file size, basically)
  • load image tags in the ImageData structure (see below)
  • upload files to the ImageData structure (if necessary)
  • displayed image and tags for user editing (in the image box and several text boxes)
  • allow editing fields and renaming a file
  • write changes to the image file
  • go to the next file.

Example:

  • Download Image0001.jpg. Fill in the StructureData Structure fields.
  • Enter a description: "Lokkat ceiling cat sends a son."
  • ImageData.FileName changed to "lolcat-ceiling-cat-send-son.jpg".
  • ImageData.Name, .Keywords, .Title, .Subject and .Comments changed to "lolcat ceiling cat sends son."
  • Save the file with a new file name and save all new tag fields.

( 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

+3
2

EDIT: 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")

, . , .

+1
    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
0

Source: https://habr.com/ru/post/1783430/


All Articles