Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java : How to resize buffered image in pixels?

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();
like image 242
iamtheexp01 Avatar asked Jul 27 '26 17:07

iamtheexp01


1 Answers

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.

like image 90
Riyad Kalla Avatar answered Jul 30 '26 08:07

Riyad Kalla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!