My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Getting_started  
A simple introduction
Featured, Phase-Implementation
Updated Aug 2, 2010 by m%nobel-...@gtempaccount.com

Introduction

This will guide you through how to rescale images using this library.

A simple rescale

Lets say that you have a BufferedImage instance called tomato that should be rescaled to 100x200. If you want a high quality rescale, you should choose the ResampleOp class:

ResampleOp  resampleOp = new ResampleOp (100,200);
BufferedImage rescaledTomato = resampleOp.filter(tomato, null);

Tip: You might need to increase your maximum heap. This can be done using the -Xmx parameter, such as: java -Xmx512m MyJavaClass

Using Unsharpen Filter

Let's improve the quality a bit more adding a unsharpen filter to the final image. This will remove some of blur, that a rescale operation creates.

ResampleOp  resampleOp = new ResampleOp (100,200);
resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
BufferedImage rescaledTomato = resampleOp.filter(tomato, null);

Adding a listener

If your tomato image was very large, this might take some time. The following code add a change listener so the user can see that the computer is actually is working.

ResampleOp  resampleOp = new ResampleOp (100,200);
resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
resampleOp.addProgressListener(new ProgressListener() {
  public void notifyProgress(float fraction) {
    System.out.printf("Still working - %f percent %n",fraction*100);
  }
});
BufferedImage rescaledTomato = resampleOp.filter(tomato, null);
Comment by perhac.p...@gmail.com, Nov 4, 2011

Could you please add some more examples. I was particularly interested in using this library for down-sizing images uploaded to my spring mvc web application. Could you perhaps provide a full example for that?

The library looks very interesting though, and the third party Filters are also awesome.

Comment by chate...@gmail.com, Jan 31, 2012

works very well with this sample code:

public class Test {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		File f = new File("C:\\image resizer\\0776171_L.jpg");
		BufferedImage src = ImageIO.read(f);
		
		ResampleOp resampleOp = new ResampleOp (76,76);
		resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.VerySharp);
		BufferedImage rescaled = resampleOp.filter(src, null);
		
		ImageIO.write(rescaled, "JPG", 
				new File("C:\\image resizer\\0776171_L76.jpg"));
	}
}
Comment by vaibhavk...@gmail.com, May 7, 2012

If it not works, you can do like this

BufferedImage? rescaled = resampleOp.doFilter(src, null, 76, 76);


Sign in to add a comment
Powered by Google Project Hosting