.NET: Specific TIFF files cannot be saved

We are attempting to use the Aspose.Imaging .NET library to set XMP metadata in TIFF files. This generally works as expected for most files. We’ve encountered two files that cannot be saved without the library throwing an exception.

REVSD4C_4.tif and REVSD4C_5.tif have been zipped into TIF.zip

Aspose.Imaging.CoreExceptions.ImageFormats.TiffImageException “Unsupported bits per sample 8, 0, 0, 8 count.”:
at � .� (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .� � (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at Aspose.Imaging.FileFormats.Tiff.TiffFrame+�.Process (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .Process (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .� � (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .� (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .� (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .� � (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .LoadPartialArgb32Pixels (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .� � (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .� (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .� (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at � .� � (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at Aspose.Imaging.RasterImage.� (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at Aspose.Imaging.RasterImage.LoadPartialArgb32Pixels (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at Aspose.Imaging.FileFormats.Tiff.TiffFrame.� (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at Aspose.Imaging.FileFormats.Tiff.TiffImage.� (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at Aspose.Imaging.FileFormats.Tiff.TiffImage.SaveData (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)
at Aspose.Imaging.DataStreamSupporter.Save (Aspose.Imaging undefined, Version=21.12.0.0 undefined, Culture=neutral undefined, PublicKeyToken=716fcc553a201e56 undefined)

@amytant, Please provide sample code you use to reproduce issue.

Code:

using (var inputStream = System.IO.File.OpenRead(localInputPath))
using (var img = Image.Load(inputStream))
{
XmpPacketWrapper xmp = ((RasterImage)img).XmpData;
if (xmp == null)
{
XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString());
XmpTrailerPi xmpTrailer = new XmpTrailerPi(true);
XmpMeta xmpMeta = new XmpMeta();
xmp = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
((RasterImage)img).XmpData = xmp;
}
if (xmp.ContainsPackage(“dc”))
{
foreach (var xmpPackage in xmp.Packages)
{
if (xmpPackage.NamespaceUri.Trim().ToLower() == “DCMI: DCMI Metadata Terms”)
{
if (xmpPackage.ContainsKey(“dc:keywords”))
{
xmpPackage[“dc:keywords”] = “2021”;
}
else
{
xmpPackage.AddValue(“dc:keywords”, “2021”);
}
}
}
}
else
{
XmpBasicPackage xmpPackage = new XmpBasicPackage(“dc”, “DCMI: DCMI Metadata Terms”);
xmpPackage .AddValue(“dc:keywords”, “2021”);
xmp.AddPackage(xmpPackage );
}
using (var outputStream = new MemoryStream())
{
img.Save(outputStream);
using (var fileStream = System.IO.File.Create(localOutputPath))
{
outputStream.Seek(0, System.IO.SeekOrigin.Begin);
outputStream.CopyTo(fileStream);
}
}
}

It fails on img.Save(outputStream);

@amytant,please try next code to process xmp:

using (RasterImage image = (RasterImage)Image.Load(@"c:\Users\USER\Downloads\REVSD4C_5.tif"))
           {
               XmpPacketWrapper xmp = ((RasterImage)image).XmpData;
               if (xmp == null)
               {
                   XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString());
                   XmpTrailerPi xmpTrailer = new XmpTrailerPi(true);
                   XmpMeta xmpMeta = new XmpMeta();
                   xmp = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
                   ((RasterImage)image).XmpData = xmp;
               }
               if (xmp.ContainsPackage("dc"))
               {
                   foreach (var xmpPackage in xmp.Packages)
                   {
                       if (xmpPackage.NamespaceUri.Trim().ToLower() == "http://purl.org/dc/elements/1.1/")
                       {
                           if (xmpPackage.ContainsKey("dc:keywords"))
                           {
                               xmpPackage["dc:keywords"] = "2021";
                           }
                           else
                           {
                               xmpPackage.AddValue("dc:keywords", "2021");
                           }
                       }
                   }
               }
               else
               {
                   XmpBasicPackage xmpPackage = new XmpBasicPackage("dc", "http://purl.org/dc/elements/1.1/");
                   xmpPackage.AddValue("dc:keywords", "2021");
                   xmp.AddPackage(xmpPackage);
               }


               image.Save(@"c:\Users\USER\Downloads\res.tiff", new TiffOptions(TiffExpectedFormat.TiffJpegRgb));
           }

Also we have noticed, that saving of those files produces artifact, so we created task IMAGINGNET-5255 to fix this.

1 Like

Thank you for the code, passing along TiffExpectedFormat.TiffJpegRgb as a TiffOption during image.Save() does make the Save succeed.

Can you clarify what artifact is produced during the saving of these files?

@amytant, As we see final image has color based artifacts, so that it does not match input one.

@samer.el-khatib4aspose Can I ask what the current status for this bug fix task IMAGINGNET-5255 is? This is a problem for our customers that we would like to resolve as soon as possible, which requires a fix for the Aspose bug where the saving of these files produces color based artifacts.

@amytant
Thank you for coming back. Unfortunately, as per our current workload, we’d not chance to work on the issue, yet. But we’ve increased its priority taking in consideration your request.

@aifeigin4aspose This forum thread says that IMAGINGNET-5255 has been resolved. When can we expect the bug fix to be released?

@amytant
The fix is included in release 22.08, which is scheduled for August 2022.

The issues you have found earlier (filed as IMAGINGNET-5255) have been fixed in this update. This message was posted using Bugs notification tool by samer.el-khatib4aspose