Question

I am doing a web project on media manager. I upload high resolution images and need to convert these images to low resolution, so that the resulting image is compressed into a smaller size. How is this possible using Java?

Please post source code, if possible.

Thanks, Naveen

Was it helpful?

Solution

not sure if I got it right, but if you want to change the size of an image, the Image class has a getScaledInstance method:

Image theImage = ...
Image scaled = theImage.getScaledInstance(32, -1, Image.SCALE_FAST);

For details see the documentation of Image

OTHER TIPS

I've seen JAI used for this purpose.

You could add an parameter onto your image reader if you don't need to do anything with the high-res image, e.g.

ImageReadParam param = reader.getDefaultReadParam();
param.setSourceSubsampling(4, 4, 0, 0);
img = reader.read(0);

This will skip 3 out of 4 rows/column in the source data.

If you're running on a Linux server with the imagemagick binaries installed, you could just do an Runtime.getRuntime.exec() on /usr/bin/convert. Just make sure you read/write to unique names (you can use File.createTempFile() to ensure that).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top