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)