none
Editing the Tag of an Image File.

    Question

  • Hi. I am renaming Image Files in my app. using the following code string

     My.Computer.FileSystem.RenameFile(NewImagePath, Title & " " & ID & ".png")
    
    Can someone help me with a simelar way to Edit the Image's Tag?


    Hendri Bissolati noviceprogrammer@vodamail.co.za
    Tuesday, August 9, 2011 9:43 AM

Answers

  • Ok this one was a little difficult to find took 2 Hours to find, I will be explaining the complete process, Lets see if that time pays or not.


    Windows stores this information in the EXIF information in the image.
    You can access these properties by loading up the image into a
    System.Drawing.Image and searching through the PropertyItems
    collection.

    Each item in the PropertyItems collection has a key/value combination.
    The key coincides with a number set forth by the EXIF standard, and
    maps to various information about the image (exposure, shutter speed,
    etc).

    Microsoft uses this to store additional information which shows up on
    the properties of the image in Windows. The keys which correlate with
    these are:

    Title = 0x9C9B
    Comments = 0x9C9C
    Keywords\Tag = 0x9C9D   This is what you are looking for
    Subject = 0x9C9E

    The values are stored as Unicode strings in the Value property of the
    PropertyItem, and can be extracted using the static
    System.Text.ASCIIEncoding.Unicode.GetString() method.

    One more thing, only some of the properties are stored as Unicode
    strings. Others are encoded differently, and will need additional
    processing, because they represent things like rational numbers, times,
    etc. Reading up on the EXIF standard will help to determine how to
    parse this type of information.

    The PropertyInfo class also exposes a Type property. The values for
    this map to what data is in there, and this may help you to determine
    how to process it:

    1 = Unicode string, byte, or raw byte array
    2 = ASCII string
    3 = Short
    4 = UInt32 (mainly used for lookups, orientation, etc)
    5 = Rational (such as 3/4) Its expressed as two longs
    7 = Undefined/Proprietary (typically a byte)
    9 = Signed Long. (a 32-bit signed integer (2's complement notation))
    10 = Signed Rational (Its expressed as two signed longs)

    Some of the more interesting information and their keys are:

    DateTaken = 0x9003
    ExposureBias = 0x9204
    MaxAperture = 0x9205
    LightSource = 0x9208
    Flash = 0x9209
    FocalLength = 0x920A
    FNumber = 0x829D
    ExposureTime = 0x829A
    MeteringMode = 0x9207

    http://www.vbforums.com/showthread.php?t=466484

    CODE:

    Public Class Form1
    
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim image1 As System.Drawing.Image
        Dim Title, Author, Keywords, Subject As String
    
        image1 = Drawing.Image.FromFile("C:\Users\faraz\Pictures\2a.jpg")
        Dim allProperty() As System.Drawing.Imaging.PropertyItem = image1.PropertyItems
    
        For Each propTemp As System.Drawing.Imaging.PropertyItem In allProperty
          Select Case propTemp.Id
            Case 40091 'Title
              Title = System.Text.ASCIIEncoding.Unicode.GetString(propTemp.Value)
    
            Case 40093 'Author
              Author = System.Text.ASCIIEncoding.Unicode.GetString(propTemp.Value)
    
            Case 40094 'Keywords
              Keywords = System.Text.ASCIIEncoding.Unicode.GetString(propTemp.Value)
    
            Case 40095 'Subject
              Subject = System.Text.ASCIIEncoding.Unicode.GetString(propTemp.Value)
    
          End Select
        Next
    
        ' MsgBox(Title)
        ' MsgBox(Author)
        MsgBox(Keywords)
        'MsgBox(Subject)
    
      End Sub
    End Class
    



    Faraz

    Tuesday, August 9, 2011 3:40 PM
  • Code to edit Tags

     

    Dim image1 As System.Drawing.Bitmap
    image1 = New System.Drawing.Bitmap("d:\2a.jpg")
    
    Dim pItem As System.Drawing.Imaging.PropertyItem = image1.PropertyItems(0)
    
    pItem.Id = 40094 'Location code of TAG Filed
    Dim byt As Byte() = {65} ' 65 asci code of "A"
    pItem.Value = byt
    image1.SetPropertyItem(pItem)
    
    Dim b As New Bitmap(image1)
    
    b.SetPropertyItem(pItem)
    
    b.Save("d:\2atest.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
    b.Dispose()
    


     


    Faraz
    Wednesday, August 10, 2011 3:03 AM

All replies

  • Hi. I am renaming Image Files in my app. using the following code string

     

     My.Computer.FileSystem.RenameFile(NewImagePath, Title & " " & ID & ".png")
    
    Can someone help me with a simelar way to Edit the Image's Tag?

     


    Hendri Bissolati noviceprogrammer@vodamail.co.za

    All image tags listed here

    http://msdn.microsoft.com/en-us/library/ms534418%28VS.85%29.aspx

    To edit tags

    http://stackoverflow.com/questions/4882130/how-do-i-edit-jpg-file-title-subject-comments-and-tags-keywords

    CODE:

    image.SetPropertyItem(0x0112)
    



    Faraz
    Tuesday, August 9, 2011 10:37 AM
  • Hi. I am renaming Image Files in my app. using the following code string

     

     My.Computer.FileSystem.RenameFile(NewImagePath, Title & " " & ID & ".png")
    
    Can someone help me with a simelar way to Edit the Image's Tag?

     


    Hendri Bissolati noviceprogrammer@vodamail.co.za

    All image tags listed here

    http://msdn.microsoft.com/en-us/library/ms534418%28VS.85%29.aspx

    To edit tags

    http://stackoverflow.com/questions/4882130/how-do-i-edit-jpg-file-title-subject-comments-and-tags-keywords

    CODE:

     

    image.SetPropertyItem(0x0112)
    


    I dont anderstand, how do I use this    image.SetPropertyItem(0x0112)


    Faraz


    Hendri Bissolati noviceprogrammer@vodamail.co.za
    Tuesday, August 9, 2011 10:44 AM
  • See the link To edit tags

    http://stackoverflow.com/questions/4882130/how-do-i-edit-jpg-file-title-subject-comments-and-tags-keywords

     

    Dim image As Image = System.Drawing.Image.FromFile("path/to/file.jpg")
    image.SetPropertyItem(0x0112)
    

    0x0112 is the tag PropertyTagOrientation see the link provided for other tags

    http://msdn.microsoft.com/en-us/library/ms534418%28VS.85%29.aspx

     


    Faraz
    Tuesday, August 9, 2011 10:48 AM
  • See the link To edit tags

    http://stackoverflow.com/questions/4882130/how-do-i-edit-jpg-file-title-subject-comments-and-tags-keywords

     

    Dim image As Image = System.Drawing.Image.FromFile("path/to/file.jpg")
    image.SetPropertyItem(0x0112)
    

    0x0112 is the tag PropertyTagOrientation see the link provided for other tags

    http://msdn.microsoft.com/en-us/library/ms534418%28VS.85%29.aspx

     


    Faraz


    Thanks for your help, butt I dont get it.  Ether I am stuped or you dont anderstand my question, let me refraz.

    Hi. I am renaming Image Files in my app. using the following code string

     

    Dim Title As String = TitleLabel.Text

    Dim ID As Integer = IDLabel.Text

    My.Computer.FileSystem.RenameFile(NewImagePath, Title & " " & ID & ".png")

    At the same time the Image is renamed I need the Tag to be changed = ID

     


    Hendri Bissolati noviceprogrammer@vodamail.co.za


    Hendri Bissolati noviceprogrammer@vodamail.co.za
    Tuesday, August 9, 2011 11:01 AM
  • Please clarify to me , what do you mean by tag
    Faraz
    Tuesday, August 9, 2011 11:09 AM
  • Please clarify to me , what do you mean by tag
    Faraz


    The Tag is someting you do not see, same as the Tag of an TextBox on the form. I need the app. to inentifi an Image by not using the Image's Name.

    Is this even poseble? 


    Hendri Bissolati noviceprogrammer@vodamail.co.za
    Tuesday, August 9, 2011 11:15 AM
  • For example sorting image's by there tags in a folder.

    Jpg -> Properties -> Details -> Description -> Tag

    is this what you want to change.


    Faraz
    Tuesday, August 9, 2011 11:38 AM
  • For example sorting image's by there tags in a folder.

    Jpg -> Properties -> Details -> Description -> Tag

    is this what you want to change.


    Faraz

    Yes, the Tag
    Hendri Bissolati noviceprogrammer@vodamail.co.za
    Tuesday, August 9, 2011 12:28 PM
  • http://www.codeproject.com/KB/graphics/EXIF_tag_Editor.aspx

    The above examples shows it but it is in C#, I need some time to build code to edit Tag. ( I manually edit the Tag to "2" )

     


    Faraz
    Tuesday, August 9, 2011 12:36 PM
  • Ok this one was a little difficult to find took 2 Hours to find, I will be explaining the complete process, Lets see if that time pays or not.


    Windows stores this information in the EXIF information in the image.
    You can access these properties by loading up the image into a
    System.Drawing.Image and searching through the PropertyItems
    collection.

    Each item in the PropertyItems collection has a key/value combination.
    The key coincides with a number set forth by the EXIF standard, and
    maps to various information about the image (exposure, shutter speed,
    etc).

    Microsoft uses this to store additional information which shows up on
    the properties of the image in Windows. The keys which correlate with
    these are:

    Title = 0x9C9B
    Comments = 0x9C9C
    Keywords\Tag = 0x9C9D   This is what you are looking for
    Subject = 0x9C9E

    The values are stored as Unicode strings in the Value property of the
    PropertyItem, and can be extracted using the static
    System.Text.ASCIIEncoding.Unicode.GetString() method.

    One more thing, only some of the properties are stored as Unicode
    strings. Others are encoded differently, and will need additional
    processing, because they represent things like rational numbers, times,
    etc. Reading up on the EXIF standard will help to determine how to
    parse this type of information.

    The PropertyInfo class also exposes a Type property. The values for
    this map to what data is in there, and this may help you to determine
    how to process it:

    1 = Unicode string, byte, or raw byte array
    2 = ASCII string
    3 = Short
    4 = UInt32 (mainly used for lookups, orientation, etc)
    5 = Rational (such as 3/4) Its expressed as two longs
    7 = Undefined/Proprietary (typically a byte)
    9 = Signed Long. (a 32-bit signed integer (2's complement notation))
    10 = Signed Rational (Its expressed as two signed longs)

    Some of the more interesting information and their keys are:

    DateTaken = 0x9003
    ExposureBias = 0x9204
    MaxAperture = 0x9205
    LightSource = 0x9208
    Flash = 0x9209
    FocalLength = 0x920A
    FNumber = 0x829D
    ExposureTime = 0x829A
    MeteringMode = 0x9207

    http://www.vbforums.com/showthread.php?t=466484

    CODE:

    Public Class Form1
    
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim image1 As System.Drawing.Image
        Dim Title, Author, Keywords, Subject As String
    
        image1 = Drawing.Image.FromFile("C:\Users\faraz\Pictures\2a.jpg")
        Dim allProperty() As System.Drawing.Imaging.PropertyItem = image1.PropertyItems
    
        For Each propTemp As System.Drawing.Imaging.PropertyItem In allProperty
          Select Case propTemp.Id
            Case 40091 'Title
              Title = System.Text.ASCIIEncoding.Unicode.GetString(propTemp.Value)
    
            Case 40093 'Author
              Author = System.Text.ASCIIEncoding.Unicode.GetString(propTemp.Value)
    
            Case 40094 'Keywords
              Keywords = System.Text.ASCIIEncoding.Unicode.GetString(propTemp.Value)
    
            Case 40095 'Subject
              Subject = System.Text.ASCIIEncoding.Unicode.GetString(propTemp.Value)
    
          End Select
        Next
    
        ' MsgBox(Title)
        ' MsgBox(Author)
        MsgBox(Keywords)
        'MsgBox(Subject)
    
      End Sub
    End Class
    



    Faraz

    Tuesday, August 9, 2011 3:40 PM
  • Code to edit Tags

     

    Dim image1 As System.Drawing.Bitmap
    image1 = New System.Drawing.Bitmap("d:\2a.jpg")
    
    Dim pItem As System.Drawing.Imaging.PropertyItem = image1.PropertyItems(0)
    
    pItem.Id = 40094 'Location code of TAG Filed
    Dim byt As Byte() = {65} ' 65 asci code of "A"
    pItem.Value = byt
    image1.SetPropertyItem(pItem)
    
    Dim b As New Bitmap(image1)
    
    b.SetPropertyItem(pItem)
    
    b.Save("d:\2atest.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
    b.Dispose()
    


     


    Faraz
    Wednesday, August 10, 2011 3:03 AM