Created
June 16, 2010 15:47
-
-
Save jkriss/440874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.sun.image.codec.jpeg.*; | |
ByteArrayOutputStream out = null; | |
BufferedImage img = null; | |
JPEGImageEncoder encoder = null; | |
JPEGEncodeParam encpar = null; | |
void setup() { | |
size(200,200); | |
out = new ByteArrayOutputStream(); | |
img = new BufferedImage(1024, 768, BufferedImage.TYPE_USHORT_GRAY); | |
encoder = JPEGCodec.createJPEGEncoder(out); | |
encpar = encoder.getDefaultJPEGEncodeParam(img); | |
} | |
void draw() { | |
try { | |
makeJpeg(img); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
byte[] makeJpeg(BufferedImage img) throws Exception { | |
out.reset(); | |
encpar.setQuality(0.7,true); // 0.0-1.0, force baseline | |
encoder.setJPEGEncodeParam(encpar); | |
encoder.encode(img); | |
return out.toByteArray(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment