We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Save screen directly to Jpg > code
Page Index Toggle Pages: 1
Save screen directly to Jpg > code (Read 2644 times)
Save screen directly to Jpg > code
May 27th, 2005, 11:17am
 
Hey, got a bit tired of converting the tif-files to jpg before sending them to friends, so .. i just wrote this little function:

Code:

import com.sun.image.codec.jpeg.*;

void SaveJpg(String fname){
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedImage img = new BufferedImage(width, height, 2);
img = (BufferedImage)createImage(width, height);
loadPixels();
for(int i = 0; i < width; i++)
{
for(int j = 0; j < height; j++)
{
int id = j*width+i;
img.setRGB(i,j, pixels[id]);
}
}
try{
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(img);
}
catch(FileNotFoundException e){
System.out.println(e);
}
catch(IOException ioe){
System.out.println(ioe);
}
byte [] a = out.toByteArray();
saveBytes(fname,a);
}



Enjoy


-seltar
Re: Save screen directly to Jpg > code
Reply #1 - May 30th, 2005, 10:02pm
 
Wah cool thanks!! :]
Re: Save screen directly to Jpg > code
Reply #2 - May 30th, 2005, 11:48pm
 
No problem Smiley
add this after JPEGImageEncoder, for qualitysettings..
Code:

JPEGEncodeParam encpar = encoder.getDefaultJPEGEncodeParam(img);
encpar.setQuality(1,true); // 0.0-1.0, force baseline (?)


---EDIT---
AND change encoder.encode(img); to encoder.encode(img,encpar);

-seltar
Re: Save screen directly to Jpg > code
Reply #3 - May 31st, 2005, 9:01pm
 
You might wanna check this thread from the Processing ALPHA board full of 'ancient thoughts and moldy code' Wink

http://processing.org/discourse/yabb/YaBB.cgi?board=Tools;action=display;num=1066742994

Koenie
Re: Save screen directly to Jpg > code
Reply #4 - May 31st, 2005, 9:24pm
 
wow.. was a lot of cool stuff in there.. to bad all the code-links were gone.. only some posted stuff, and that didn't seem like the final product..

but still, thanks for pointing me there, got a lot of pointers on how to further develop my function:)

-seltar
Re: Save screen directly to Jpg > code
Reply #5 - Jun 1st, 2005, 8:05pm
 
If you're looking for some specific code-links, I might have some of the old code back in my moldy 0048-0065 folders.

Koenie
Page Index Toggle Pages: 1