2

I'm trying clear some property tag item from tif file.
My test code is:

Image sourceImg = new Bitmap("A10034.tif");
Image img = (Image)sourceImg.Clone();
sourceImg.Dispose();

PropertyItem[] propertyItemsList = img.PropertyItems;
foreach (PropertyItem property in propertyItemsList)
{
    if ((property.Id == 270 || property.Id == 271 || property.Id == 272 || property.Id == 305 ||
         property.Id == 315 || property.Id == 316) || (property.Id > 320 && property.Id != 33432))
    {
        img.RemovePropertyItem(property.Id);
    }
}

ImageCodecInfo Encoder = GetEncoderInfo("image/tiff");
EncoderParameters EncoderParams = new EncoderParameters(2);
EncoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (Int64)EncoderValue.CompressionNone);
EncoderParams.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
if (System.IO.File.Exists("cleared_A10034.tif"))
{
    System.IO.File.Delete("cleared_A10034.tif");
}
img.Save("cleared_A10034.tif", Encoder, EncoderParams);
img.Dispose();

This works in WinXp and Win 8 but don't work in Win 7.
All tags in destination file same as source file in Win7. Nothing delete.
Any ideas?
Thanks.
You can download test project if needed.

Igor
  • 61
  • 6

1 Answers1

4

Problem resolved.
I added image rotate before saving and all works now.

img.RotateFlip(RotateFlipType.Rotate180FlipNone);
img.RotateFlip(RotateFlipType.Rotate180FlipNone);
img.Save("cleared_" + fileName, Encoder, EncoderParams);

Strange, but this works.

Igor
  • 61
  • 6
  • The mentioned method works for me too. I couldn't find why properties weren't getting set either. I tried setting values as well but no luck there either. RemovePropertyItem is likely not setting the changes to the image but other methods like RotatateFlip is. Possible bug in the System.Drawing.Image library. – wonster Apr 03 '14 at 23:26