This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 41633
    
  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: 41633
    
  55
Is "enc" null? If not, post the stack trace.
 
 
subject: how to decrease the size of the jpeg image file?