Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

how to decrease the size of the jpeg image file?  RSS feed

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the setQuality method of JPEGEncodeParam. It's documented here.

 
akash kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf Dittmer! Thanks for the help provided by you.
 
akash kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is "enc" null? If not, post the stack trace.
 
That feels good. Thanks. Here's a tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!