3

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:

  1. load image into memory
  2. convert bmp files to jpgs if needed (for a smaller file size, mostly)
  3. load image tags into ImageData Structure (see below)
  4. load file data into ImageData Structure (where needed)
  5. display image and tags for user to edit (In a Picture Box and several Text Boxes)
  6. allow editing of fields and renaming of the file
  7. write the changes to the image file
  8. go to next file.

Example:

  1. Load Image0001.jpg. Populate ImageData Structure fields.
  2. Type in Description: "lolcat ceiling cat sends son".
  3. ImageData.FileName changed to "lolcat-ceiling-cat-sends-son.jpg".
  4. ImageData.Name, .Keywords, .Title, .Subject, and .Comments changed to "lolcat ceiling cat sends son".
  5. Save file with new filename and save all new tag fields.

(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:

  • 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.aspx

  • Requires external DLL
    [http://]www.codeproject.com/KB/GDI-plus/ImageInfo.aspx

  • External Software required
    [http://]stackoverflow.com/questions/3313474/write-metadata-to-png-image-in-net

  • Old Data ~ Visual Studio 2005 and .NET 2.0
    [http://]www.codeproject.com/KB/graphics/MetaDataAccess.aspx

  • Convert to BMP: Looks useful
    [http://]www.freevbcode.com/ShowCode.Asp?ID=5799

1
  • You haven't actually asked a question or if you have its so broad that we can't determine what you actually want help with. Is your question "How can I write metadata to a JPEG" (I think only the JPEG and TIFF formats support structured arbitrary metadata and TIFF isn't too web friendly.) Try breaking your post down into individual problems for us to help you with.
    – Chris Haas
    Jan 4, 2011 at 17:49

2 Answers 2

1

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.

1
  • That's the kind of nudge I was looking for. Thank you! This looking like it will have all that I need to get started. Jan 5, 2011 at 14:13
0
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.