How to create a graphics file in Java?
I need to create a 2D image file by simply setting colour of every point and then also output text at specific coordinates.
Can you recommend the easiest开发者_运维问答 library for this and provide an example?
See http://java.sun.com/javase/technologies/desktop/media/2D/
Namely http://download.oracle.com/javase/1.4.2/docs/guide/2d/spec.html
Namely http://download.oracle.com/javase/1.4.2/docs/api/java/awt/image/WritableRaster.html
Example:
static final int X = 380, Y = 250;
static BufferedImage img = new BufferedImage(X, Y, BufferedImage.TYPE_INT_RGB);
static public void main(String[] args){
WritableRaster wr = img.getRaster();
int[] a = new int[3]; // 96 bit pixels
a[0] = ...
a[1] = ...
a[2] = ...
wr.setPixel(20, 20, a);
}
精彩评论