Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compress Image before Saving to disk in Java

Is it possible to compress an image before saving it? I'm using the Robot class to capture images, and it returns a BufferedImage. How can I compress this image and then save it?

like image 768
knurdy Avatar asked Jun 22 '26 09:06

knurdy


1 Answers

.png files are (losslessly) compressed images.

You can use ImageIO.write() to save a .png image:

ImageIO.write(myBufferedImage, "png", outputfile);
like image 173
BlueRaja - Danny Pflughoeft Avatar answered Jun 23 '26 21:06

BlueRaja - Danny Pflughoeft



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!