iam currently using your Aspose Image library latest version 23.5 in a Java project and am facing an issue that I need help with.
Here’s a brief summary of my issue:
I’m attempting to load an image file and subsequently save it. However, during the process, an exception with the message “Image export failed” is being thrown
Here’s the test code:
public static void main(String[] args) {
Image image;
image =Image.load(“33.emf”);
long format = image.getFileFormat();
System.out.println("Picture type = "+ counter + getPictureType(format));
ByteArrayOutputStream output = new ByteArrayOutputStream();
ImageOptionsBase imageOptions;
String action;
System.out.println("image format of image = “+counter +” " + getPictureType(format));
if (format == FileFormat.Jpeg || format == FileFormat.Jpeg2000) {
imageOptions = new JpegOptions();
System.out.println("Picture converted to JPEG");
action = "Picture converted to JPEG";
} else {
System.out.println("Picture converted to PNG");
imageOptions = getPngOptions(image, format);
action = "Picture converted to PNG";
}
try {
image.save(output, imageOptions);
} catch (Exception e) {
System.out.println("extipetion when save file = "+counter + e.getMessage());
logger.warning("save image failed");
image.dispose();
throw new RuntimeException();
}
logger.fine(action);
image.dispose();
}
public static PngOptions getPngOptions(Image image, long format) {
float scale = 1;
PngOptions pngOptions = new PngOptions();
pngOptions.setColorType(PngColorType.TruecolorWithAlpha);
VectorRasterizationOptions rasterizationOptions = null;
if (format == FileFormat.Emf) {
rasterizationOptions = new EmfRasterizationOptions();
try {
if(null!=image.getOriginalOptions().getResolutionSettings()) {
pngOptions.setResolutionSettings(image.getOriginalOptions().getResolutionSettings());
}
} catch (Exception e) {
System.out.println(“extipetion in getResolutionSettings emf”);
}
} else if (format == FileFormat.Wmf) {
rasterizationOptions = new WmfRasterizationOptions();
scale = 1.5f;
}
if (rasterizationOptions != null) {
rasterizationOptions.setPageSize(new SizeF(image.getWidth()*scale, image.getHeight()*scale));
rasterizationOptions.setBackgroundColor(image.hasBackgroundColor() ? image.getBackgroundColor() : Color.getTransparent());
pngOptions.setVectorRasterizationOptions(rasterizationOptions);
}
return pngOptions;
}
img.7z (18.6 KB)
Unfortunately, I haven’t been able to extract a complete stack trace. However, the exception message is: “Image export failed”.
Any assistance you could provide would be greatly appreciated. Please let me know if you require additional information to diagnose this issue.
Best regards,
pavel
i add 2 emf files as an example