Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Image Compression  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like to compress an image to a specific size if the original size exceeds a limit. How can I do that using Java?

Any sample codes or guidelines are very much appreciated.

Thank you very much.
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Are you talking about compression in the sense of reducing the file size but keeping the file contents (like ZIP does), or about using compression capabilities of the image formats themselves (which would effect image quality)? If the latter, have a look at this example. It demonstrates writing a JPEG file using the ImageIO API, and lets the user vary the compression/quality.
[ September 07, 2006: Message edited by: Ulf Dittmer ]
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to use JAI. It is the image processing API in Java
Java Advanced Imaging (JAI) API
 
Rujitha Patel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My intention is to store images in the database as a byte[]. The image data are taken as input from the customers through a web application. Therefore the input image can be any format and any size.

My web application is reading the images as byte[]. Therefore the compression program should take a byte[] as a parameter and return a byte[] of the compressed image.

What Ulf Dittmer suggested is something near to my needs but not complete. Thank you very much. Any further help very much appreciated.
 
We noticed he had no friends. So we gave him this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!