wood burning stoves 2.0*
The moose likes Java in General and the fly likes how to decrease the size of the jpeg image file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to decrease the size of the jpeg image file?" Watch "how to decrease the size of the jpeg image file?" New topic
Author

how to decrease the size of the jpeg image file?

akash kumar
Ranch Hand

Joined: Jun 13, 2007
Posts: 63
Hi friends i'm using this code for capturing the screen . i want to set the quality of the image . how to do that?


baos = new ByteArrayOutputStream();
com.sun.image.codec.jpeg.JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder( baos ); // encode the image to jpg
enc.encode(BI);
FileOutputStream fos=new FileOutputStream("Screen_Shot_"+count+".jpg");
BufferedOutputStream bos = new BufferedOutputStream( fos );
byte[] b = baos.toByteArray();
bos.write( b );
bos.flush();
bos.close();
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
You can use the setQuality method of JPEGEncodeParam. It's documented here.



Ping & DNS - my free Android networking tools app
akash kumar
Ranch Hand

Joined: Jun 13, 2007
Posts: 63
Hi Ulf Dittmer! Thanks for the help provided by you.
akash kumar
Ranch Hand

Joined: Jun 13, 2007
Posts: 63
Hi Ulf Dittmer!

I'm having problem. This line of code is raising nullpointer exception "JPEGEncodeParam param = enc.getJPEGEncodeParam();". what might be the problem?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Is "enc" null? If not, post the stack trace.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to decrease the size of the jpeg image file?