如何用Java创建图形文件?

时间:2011-02-04 23:56:11

标签: java graphics

我需要通过简单地设置每个点的颜色来创建2D图像文件,然后在特定坐标处输出文本。

您能为此推荐最简单的库并提供示例吗?

1 个答案:

答案 0 :(得分:1)

http://java.sun.com/javase/technologies/desktop/media/2D/
http://download.oracle.com/javase/1.4.2/docs/guide/2d/spec.html
http://download.oracle.com/javase/1.4.2/docs/api/java/awt/image/WritableRaster.html

示例:

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);

 }