• Post Reply Bookmark Topic Watch Topic
  • New Topic

Image Compression  RSS feed

 
Rujitha Patel
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.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • 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 ]
 
Jason Liao
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!