Image quality decreases after resizing

Hi,

Before buying imaging component I was trying out the temporary version of Aspose.

My requirement is I need to resize high quality images but with same quality. However its happening like the quality also get reduces when it resizes to smaller dimensions. I need flexibility to resize same image different number of times with different sizes.

Please help me with below code to achieve this:

com.aspose.imaging.Image image = null;
try {
image = com.aspose.imaging.Image.load(new FileInputStream(“input.png”));


Aspose.Imaging.CreateOptions.PngCreateOptions createOptions = new Aspose.Imaging.CreateOptions.PngCreateOptions();
com.aspose.imaging.imageoptions.PngOptions createOptions = new com.aspose.imaging.imageoptions.PngOptions();
com.aspose.imaging.Source source = new com.aspose.imaging.sources.FileCreateSource(“input.png”, true);
createOptions.setSource(source);
com.aspose.imaging.Image outimage = com.aspose.imaging.Image.create(createOptions,460,288);
com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(outimage);
graphics.clear(com.aspose.imaging.Color.getWhite());
graphics.drawImage(image, outimage.getBounds());
outimage.save(“output.png”, new com.aspose.imaging.imageoptions.PngOptions());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Attached are input and output of below code.

Thanks,
Jahir

Hi Jahir,

Thank you for using Aspose products.

I have evaluated your said issue, and I am able to reproduce the similar results on my end while using the latest version of Aspose.Imaging for Java. An investigative ticket has been logged to probe further, and to rectify the problem (if applicable). The ticket Id for your future reference is IMAGING-33726. As soon as we receive any updates from the development end, we will post here.

Please note, there is another way to re-size the images by using Image.resize method. Please check the below provided sample source for your reference.

Java


com.aspose.imaging.Image image = com.aspose.imaging.Image.load(myDir+“input.png”);

image.resize(460,288);

image.save(myDir + “output.png”);

I am afraid that the quality of resultant images even with Image.resize method is similar to your provided sample.

Hi Babar,

I tried that too. But the output is same.
Please let me know if you get any resolution for this because this is one of the reason I need to buy this product.

Thanks,
Jahir

Hi Jahir,

Thank you for your kind response.

I have requested the relevant developer to schedule the investigation of this issue at earliest. As soon as I receive any updates in this regard, I will post here for your reference.

Hi,

Any update on this ?

Hi Jahir,

Thank you for your patience.

Fix for this issue will be part of Aspose.Imaging for Java v2.0.0; that is scheduled for release in first quarter of November 2013.

You may also know that each release of Aspose.Imaging for Java is ported out from an equivalent version of the .NET product. Aspose.Imaging for .NET v2.0.0 has already been released, so I have evaluated your defined scenario with .NET assemblies. The results are far better than what Aspose.Imaging for Java v1.8.0 produced. Please have look at the attachment.

Thanks for the update.

The issues you have found earlier (filed as IMAGING-33726) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Thanks, I will check.

Hi,

Its still the same issue. I have now Aspose total license but this issue is not resolved.

PFA for the input and output.

com.aspose.imaging.Image image = com.aspose.imaging.Image.load("input.jpg");

image.resize(460,288, com.aspose.imaging.ResizeType.NearestNeighbourResample);

image.save("output.jpg");

Thanks,

Amit

Hi Amit,


We are sorry for the confusion.

With Aspose.Imaging for Java 2.1.0 you have to opt the below provided approach for re-sizing while keeping the quality intact. We will fix this problem in our next major version of Aspose.Imaging for Java 2.2.0, and therefore you do not have to workaround the situation with v2.2.0.

At the moment there are some issues in the Jpeg interpreter, so when you re-size an image, the quality tends to decrease. The aforesaid problem has already been fixed in the .NET version of the product therefore we are working to auto port the base code in order to publish Aspose.Imaging for Java 2.2.0 in 2nd quarter of subsequent month.

Workaround is to convert a given image to BMP format before applying the LanczosResample type re-sizing, after that you may save the result in any other format as per your requirement. Please have a look at the following code snippet and attached resultant image for your reference.

Java

String path = myDir + “input.jpg”;
Image image = Image.load(path);
try
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
image.save(outputStream, new BmpOptions());
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
Image image2 = Image.load(inputStream);
try
{
image2.resize(460, 288, ResizeType.LanczosResample);
image2.save(myDir + “output.jpg”, new JpegOptions());
}
finally
{
image2.dispose();
}
}
finally
{
image.dispose();
}

Please feel free to write back in case you have any ambiguity.

Hi Amit,


Adding more to my previous response. If you intend to get quality result after applying the re-size then it is suggested that you should always use ResizeType.LanczosResample because it will output highly qualitative results but may work slower than ResizeType.NearestNeighbourResample. On the other hand, NearestNeighbourResample algorithm is specifically used for fast re-sizing while compromising on the image quality. This method may be useful for thumbnail generation in real time or similar processes where performance is required.

Hi,

Thanks for your suggestion and workaround. However for our purpose and for what we have bought the Aspose Total license I would like you to please update me when we have direct fix available. This is directly related to one of our business requirements.

Thanks,

Jahir

Hi Jahir,


First of all, please accept my apology for a bit delayed response.

Aspose.Imaging for Java 2.2.0 is scheduled for release in May 2014. Usually we publish the release in last quarter of each month, unless there are some special circumstances therefore it is safe to say that v2.2.0 of Aspose.Imaging for Java will be available for public use in last quarter of May 2014. We will keep you posted with updates in this regard.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.