Png image resize error / java

Hi,

Getting error while saving image after resizing. It works for jpg images and other png files. Java.

Code

        // THUMB_WIDTH = 400 - any value for attached image
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(inputStream);
        double k = (double) image.getWidth() / (double) THUMB_WIDTH;
        image.resize(THUMB_WIDTH, (int) (image.getHeight() / k));
        image.save(outputStream);
        image.close();

Exception

com.aspose.imaging.internal.Exceptions.ArgumentNullException: Value cannot be null.
Parameter name: pixels
	at com.aspose.imaging.internal.aJ.bR.process(Unknown Source)
	at com.aspose.imaging.internal.fr.h.a(Unknown Source)
	at com.aspose.imaging.internal.fr.h.b(Unknown Source)
	at com.aspose.imaging.internal.fr.h.a(Unknown Source)
	at com.aspose.imaging.internal.fr.h$b.loadPartialArgb32Pixels(Unknown Source)
	at com.aspose.imaging.internal.aJ.bx.a(Unknown Source)
	at com.aspose.imaging.internal.aJ.bA.a(Unknown Source)
	at com.aspose.imaging.internal.aJ.bA.a(Unknown Source)
	at com.aspose.imaging.internal.aJ.bA.a(Unknown Source)
	at com.aspose.imaging.internal.fr.e.loadPartialArgb32Pixels(Unknown Source)```

Png file
[png image](https://drive.google.com/file/d/1WpaHwR_5dmYmMcZGjga4Ldd7fR_iKJQk/view?usp=sharing)

@Ytrohs, We will investigate your problem and let you know as soon as possible

Hi, @Ytrohs
While we analyze this issue you can avoid this issue using Image.getOriginalOptions()

// THUMB_WIDTH = 400 - any value for attached image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(inputStream);
double k = (double) image.getWidth() / (double) THUMB_WIDTH;
image.resize(THUMB_WIDTH, (int) (image.getHeight() / k));
ImageOptionsBase options = image.getOriginalOptions();
if (options != null)
{
	options = options.deepClone();
}
image.save(outputStream, options);
image.close();

@Ytrohs
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): IMAGINGJAVA-8618

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like
ImageOptionsBase options = image.getOriginalOptions();
options = options.deepClone();
image.save(outputStream, options);

It works! Thank you!

1 Like