We have a particular image that we are converting to jpeg. Some code in our system converts jpg to jpg for legacy reasons. When converting to jpg, it creates an image that cannot be opened by Windows Photo Viewer. It successfully converts to PNG. Can you please advise? Can validate issue with aspose-imaging 19.1.
Here is some sample code:
private static byte[] convertImageToJPEG(RasterImage image, int defaultXDPI, int defaultYDPI)
{
long imageType = image.getFileFormat();
// The Aspose API currently does not support gif manipulation. In order to ensure that the transparency of a gif image is ccnverted to a white background, convert to png which preserves
// transparency and then can be removed.
if (imageType == GIF_IMAGE_TYPE)
{
byte[] pngByteArray = convertImageToPNG(image, defaultXDPI, defaultYDPI);
image = (RasterImage) Image.load(new ByteArrayInputStream(pngByteArray));
}
ByteArrayOutputStream result = new ByteArrayOutputStream();
try
{
// gist.github.com/aspose-imaging/8c9bd83e0d07145ba0c1#file-examples-src-main-java-com-aspose-imaging-examples-manipulatingpngimages-changebackgroundcolor-changebackgroundcolor-java
int[] pixels = image.loadArgb32Pixels(image.getBounds());
for (int i = 0; i < pixels.length; i++)
{
if (pixels[i] == image.getTransparentColor().toArgb())
{
pixels[i] = com.aspose.imaging.Color.getWhite().toArgb();
}
}
image.saveArgb32Pixels(image.getBounds(), pixels);
ImageOptionsBase originalOptions = image.getOriginalOptions();
JpegOptions jpegOptions = new JpegOptions();
if (originalOptions != null)
{
jpegOptions.setResolutionSettings(originalOptions.getResolutionSettings());
}
else
{
jpegOptions.setResolutionSettings(new ResolutionSetting(defaultXDPI, defaultYDPI));
}
image.save(result, jpegOptions);
}
finally
{
image.close();
}
return result.toByteArray();
}
I have observed the issue shared by you and request you to please share the generated output that fails to open in Windows Photo viewer. Please also provide the values for function parameter defaultXDPI and defaultYDPI for reference as well so that we may be able to use the code.
I have observed issue shared by you. An issue with ID IMAGINGJAVA-1181 has been created in our issue tracking system to investigate and resolve the issue. This thread has been linked with these issues so that you may be automatically notified once the issues will be resolved.
Thank you for your feedback. Secondly, your issue seems similar to one shared by you in another thread as well. Can we disregard the following thread then.
Yes the issues are similar, we can disregard the other thread. I did try the sample code. I am noticing different behaviors between the 32 bit jdk and the 64 bit jdk.
I have verified the issue status from our issue tracking system and like to share that issue has just recently been created in our issue tracking system and is pending for investigation in issues queue at the moment. We request for your patience till the time the issue gets resolved.