0
Reply

How to change and save Picture-PropertyItems

Matthias

Matthias

Jul 14 2012 6:14 AM
1.8k
I want to change a PropertyItem of a Picture and then save it in the same file.
  • Reading is no problem
  • when I try to save it in the same file, an ExternalException is thrown
  • when I start a RotateFlip (first 90 then 270 degrees) before, all is OK (2 x 180 degrees: ExternalException occurs)
  • Windows Explorer doesn't realize changing of an Item (for Example: 0x010E), other programs accept the change

What's wrong? Am I too stupid? Is C# not able? Here's the code:

                System.Drawing.Image img = System.Drawing.Image.FromFile(name);
                PropertyItem i = img.PropertyItems[0];
                i.Id = 0x010E; // PropertyTagImageDescription
                i.Type = 1;
                i.Value = System.Text.Encoding.ASCII.GetBytes(s);
                i.Len = i.Value.Length+1;
                img.SetPropertyItem(i);
                img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                img.RotateFlip(RotateFlipType.Rotate270FlipNone);
                img.Save(name, ImageFormat.Jpeg);