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

来源:互联网 发布:淘宝旅行官网 编辑:程序博客网 时间:2024/06/05 16:28
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();
}
}
0 0
原创粉丝点击