Error when opening TIFF file with Aspose.Imaging.Image.Load(filePath)

Hello!
I have an issue with opening some of TIFF files with Aspose.Imaging when trying to convert it to PDF.
I use Aspose.Imaging 24.12 for .NET and following code:

using (var image = Aspose.Imaging.Image.Load(SourcePath))
{
  saveOptions = new Aspose.Imaging.ImageOptions.PdfOptions();
  saveOptions.UseOriginalImageResolution = true;
  image.Save(TargetPath, saveOptions);
}  

When i try to open this file
Letter.zip (714.5 KB), an error occurs:

Aspose.Imaging.CoreExceptions.ImageLoadException
  HResult=0x80131500
  Message=Image loading failed.
  Source=Aspose.Imaging
  StackTrace:
   at Aspose.Imaging.Image.(StreamContainer , LoadOptions )
   at Aspose.Imaging.Image.Load(String filePath)

Inner exception is:

Unable to read file. Exception: Invalid requested xml: <?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1-701"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""  xmlns:xmp="http://ns.adobe.com/xap/1.0/">
</rdf:Description>
<rdf:Description rdf:about=""  xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/">
<xmpRights:Marked>True</xmpRights:Marked></rdf:Description>
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
                                                                                                    
</rdf:RDF></x:xmpmeta><?xpacket end="w"?>
endstream
endobj
96 0 obj
[ 0[ 750]  3[ 278]  11[ 333 333]  14[ 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 278]  35[ 1015]  40[ 667]  66[ 556]  68[ 556]  70[ 500 556 556 278]  75[ 556 222]  79[ 222 833 556 556 556]  85[ 333]  87[ 278 556]  90[ 722]  169[ 556 556]  570[ 667 656 667 542 677]  578[ 719]  580[ 583]  582[ 833 722 778 719 667 722 611 635]  592[ 740]  599[ 719]  602[ 556 573 531 365 583 556 669]  610[ 559 559 438 583 688 552 556 542 556 500 458 500 823 500 573 521 802]  630[ 521]  633[ 542]  651[ 1073] ] 
endobj
97 0 obj
<</Filter/FlateDecode/Length 40>>
stream
x����G���A���0��@*����h���#aT	

File opens normally with Windows Photo Viewer, so it seems that it isn’t broken, but Aspose.Imaging can’t handle it.
I’d like to know how this might be fixed, could you please give me some clues to achieve it?

@directum

It seems you are encountering an ImageLoadException when trying to open certain TIFF files using Aspose.Imaging. This issue may arise due to the TIFF file containing improper data layout or corrupted data strips, which can prevent the library from processing the image correctly.

To address this, you can utilize the data recovery modes provided by Aspose.Imaging. These modes allow you to load a TIFF file that has issues by replacing corrupted data with a specified color, enabling you to retrieve the rest of the data for further processing without encountering exceptions.

Here’s a sample code snippet demonstrating how to use the data recovery mode when loading a TIFF image:

using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;

public void LoadTiffWithRecovery(string sourcePath, string targetPath)
{
    // Create load options with recovery mode enabled
    var loadOptions = new LoadOptions
    {
        DataRecoveryMode = DataRecoveryMode.Recover
    };

    // Load the image with recovery options
    using (var image = Image.Load(sourcePath, loadOptions))
    {
        // Save the image to the desired format
        var saveOptions = new PdfOptions
        {
            UseOriginalImageResolution = true
        };
        image.Save(targetPath, saveOptions);
    }
}

In this code, the LoadOptions class is used to specify that data recovery should be attempted when loading the TIFF file. This should help in cases where the TIFF file is not loading correctly due to corruption or improper formatting.

If the issue persists even after trying the recovery mode, it may be worth checking the specific TIFF file for any anomalies or considering converting it to a different format using another tool before processing it with Aspose.Imaging.

For more detailed information on manipulating TIFF images and handling exceptions, you can refer to the official Aspose documentation.

Sources:
[1]: Manipulating TIFF Images - Aspose Documentation

Using LoadOptions with RecoveryMode does not help, error still occurs.

@directum Hello! Thank you for your interest in our product. We are thoroughly investigating this matter and will get back to you with a comprehensive solution as soon as possible. Your patience is appreciated.

1 Like