This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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: 41025
    
  43
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: 41025
    
  43
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
Copying a Binary (EXE) file
Servlet request object input stream time out
Conversion of GIF to JPEG
How to set the bitmap height at runtime
Coversion of ResultSet