Free Support Forum -

Java runtime error when converting tifs to multipage tif

I just bought 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});
// 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
        if (output != null) {
            // Save the result
   + "\\" + outName + ".TIF", createOptions);

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


I am attaching a sample set of (3.2 MB)


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.


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.