Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top