模擬地圖撒點,將隨機產生的一些點以圓的形式畫在畫布上並保存爲png格式的圖片

package com;

import java.awt.Color;

public class testGI {


/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub


paintImage();
}


protected static void paintImage() throws IOException {
BufferedImage image = null;
File file = new File("c:\\output\\01.png");
if (file.exists()) {
image = ImageIO.read(file);
} else {
image = new BufferedImage(10000, 10000, BufferedImage.TYPE_INT_ARGB);
}


Graphics g = image.getGraphics();
g.setColor(Color.red);
Random rand = new Random();
for (int i = 0; i < 10000; i++) { 
int x=rand.nextInt(10000);
int y=rand.nextInt(10000);
g.drawOval(x, y, 10, 10);
}

FileOutputStream out = new FileOutputStream("c:\\output\\01.png");
ImageIO.write(image, "png", out);
g.dispose();
out.close();
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章