模拟地图撒点,将随机产生的一些点以圆的形式画在画布上并保存为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();
}
}
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();
}
}
相关文章推荐
- 虚继承与虚基类的内存布局
- 关于如何用JAVA代码生成随机图片验证码
- iOS手势 清扫和长按
- Android Studio开发JNI工程
- ORA-01219:数据库未打开:仅允许在固定表/视图中查询
- storm与hadoop的对比
- css3 shape-out
- TCP/IP 问答
- 【Oracle错误集锦】:ORA-00119 & ORA-00132
- Asp.Net远程调试
- Linq 常用方法解释
- 短文本合并重复(去重)的简单有效做法
- android studio中空文件夹是否折叠
- c++复习
- javaScript实现多语言切换
- HTML中的<select>标签如何设置默认选中的选项
- 在一个字符串中查找另一个字符串出现的次数
- Android照片墙应用实现,再多的图片也不怕崩溃
- Android开发规范
- 记录锁