I need to resize the original buffered image to width 100 px with preserved width/height ratio. Below is the code am using. Could someone help me with this ? Thanks in advance.
int width = 100;
int height = 100;
BufferedImage resizedImage = new BufferedImage(width, height, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, width, height, null);
g.dispose();
You might want to take a look at imgscalr, it is a simple single class that does exactly this with a simple set of static methods to use: http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/
An example usage would look like:
BufferedImage img = Scalr.resize(src, 100);
There are a number of advanced features around quality, speed and simple image ops available to you as well if you need them and the library has been deployed in production in numerous projects and web applications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With