This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 39547
    
  27
You can use the setQuality method of JPEGEncodeParam. It's documented here.



Ping & DNS - updated with new look and Ping home screen widget
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: 39547
    
  27
Is "enc" null? If not, post the stack trace.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to decrease the size of the jpeg image file?
 
Similar Threads
Conversion of GIF to JPEG
Copying a Binary (EXE) file
Servlet request object input stream time out
How to set the bitmap height at runtime
Coversion of ResultSet