Free Support Forum - aspose.com

Java runtime error when converting tifs to multipage tif

I just bought Aspose.Imaging.java and have embedded the code below into a Java swing application, I am getting the following error when I run my code.

class com.aspose.imaging.fileformats.jpeg.JpegImage cannot be cast to class com.aspose.imaging.fileformats.tiff.TiffImage

here is my code:

public void stitchTiffs() {

    List<String> files = list;
    TiffOptions createOptions = new TiffOptions(TiffExpectedFormat.Default);
    createOptions.setBitsPerSample(new int[]{1});
    createOptions.setOrientation(TiffOrientations.TopLeft);
    createOptions.setPhotometric(TiffPhotometrics.MinIsBlack);
    createOptions.setCompression(TiffCompressions.CcittFax3);
    createOptions.setFillOrder(TiffFillOrders.Lsb2Msb);
// Create a new image by passing the TiffOptions and size of first frame, we will remove the first frame at the end, cause it will be empty
    TiffImage output = null;
    try {
        List<TiffImage> images = new ArrayList<TiffImage>();
        String sActive = null;
        for (String file : files) {
            // Create an instance of TiffImage and load the source image
            sActive = dataDir + "\\" + file;
            TiffImage input = (TiffImage) Image.load(sActive);
            images.add(input); // Do not dispose before data is fetched. Data is fetched on 'Save' later.
            for (TiffFrame frame : input.getFrames()) {
                if (output == null) {
                    // Create a new tiff image with first frame defined.
                    output = new TiffImage(TiffFrame.copyFrame(frame));
                } else {
                    // Add copied frame to destination image
                    output.addFrame(TiffFrame.copyFrame(frame));
                }
            }
        }
        if (output != null) {
            // Save the result
            output.save(outDir + "\\" + outName + ".TIF", createOptions);
        }

        for (TiffImage image : images) {
            image.close();
        }
    } catch (Exception e) {
        System.out.println("Something went wrong." + e);
    } finally {
        if (output != null) {
            output.close();
        }
    }

}

I am attaching a sample set of tifs20170112_44201706270115146.zip (3.2 MB)

@makensp,

I have worked with sample code shared by you and have been able to observe the issue specified. An issue with ID IMAGINGJAVA-1688 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Is there an earlier version of Aspose Imaging that does not have this issue – I am under some time pressure to process these files.

@makensp,

It has just been created in our issue tracking system and we request for your patience. We will share the good news with you as soon as the issue will be resolved.