您的位置:首页 > 其它

模拟地图撒点,将随机产生的一些点以圆的形式画在画布上并保存为png格式的图片

2015-07-02 16:41 316 查看
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();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: