Created
March 18, 2010 05:55
-
-
Save ulinkwo/336090 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
private void createImage(OutputStream out) { | |
int width = 100; | |
int height = 100; | |
BufferedImage buffer = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); | |
Graphics2D g = buffer.createGraphics(); | |
// set background: | |
g.setBackground(Color.BLUE); | |
g.clearRect(0, 0, width, height); | |
// set fore color: | |
g.setColor(Color.RED); | |
// start draw: | |
g.drawLine(0, 0, 99, 199); | |
// end draw: | |
g.dispose(); | |
buffer.flush(); | |
// encode: | |
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); | |
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(buffer); | |
param.setQuality(1.0f, false); | |
encoder.setJPEGEncodeParam(param); | |
try { | |
encoder.encode(buffer); | |
} catch (IOException ioe) { | |
ioe.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment