Save image after changing metadata

I have a problem saving the image after changing its metadata. Basically, I want to open my image, display it, change its EXIF ​​metadata and save it.

Firstly, I had a problem saving my image because the source file was locked (I had a general GTI + error). After reading some posts here and finding out what the problem is, I solved the blocking problem using the using keyword.

But the problem is that if I use "using", the list of Ilems properties of my image is empty, and I cannot change my metadata.

This is how I upload my image (with different tests)

this.image = new Bitmap(this.path);         // this cause lock on file

/* the following doesn't lock the file, but image.propertyItems is empty */

//using (var bmpTemp = new Bitmap(this.path))
//{
//    this.image = new Bitmap(bmpTemp);
//}

Using streamReader or MemoryStream does not help ...

And this is how I change and save my image:

 PropertyItem p = this.photo.Image.GetPropertyItem(0x5090);

 p.Id = 0x320;
 p.Type = 2; // Type ASCII
 p.Len = boxTitle.Text.Length;
 p.Value = Encoding.ASCII.GetBytes(boxTitle.Text);

 this.photo.Image.SetPropertyItem(p);
 this.photo.Image.Save(this.photo.Path);

, , "" , ?

+4
2

, , . -, Microsoft - . , . , , ( ).

+1

, Bitmap PropertyItems. PropertyItems :

using (var bmpTemp = new Bitmap(this.path))
{
    this.image = new Bitmap(bmpTemp);
    foreach (var pi in bmpTemp.PropertyItems)
    {
        this.image.SetPropertyItem(pi);
    }
}

, .

+1

All Articles