怎么用java代码模拟一张图片
发布网友
发布时间:2023-02-27 12:59
我来回答
共3个回答
热心网友
时间:2023-10-23 20:19
用java代码模拟一张图片可以这样操作:1.创建BufferedImage类
2.根据BufferedImage类得到一个Graphics2D对象
3.根据Graphics2D对象进行逻辑操作
4.处理绘图
5.将绘制好的图片写入到图片
热心网友
时间:2023-10-23 20:20
第一步:创建画布
万事开头难,我们从创建一个窗体开始,并给窗体添加画笔g。
package drawBoard_test;
import javax.swing.*;
import java.awt.*;
public class DrawUI extends JFrame {
String[] strs = {"直线","签字笔","实时直线", "谢尔宾斯基地毯","递归KLine","矩形", "圆", "实心矩形", "实心圆", "等腰三角形", "三角形", "多边形",
"改进多边形","立方体", "橡皮擦", "撤回", "保存", "打开"};
Color[] color = {Color.red,Color.white,Color.black,Color.blue};
//添加功能和颜色按钮
public void addButton(){
for(String str : strs){
JButton btn = new JButton(str);
add(btn);
}
Dimension dim = new Dimension(30,30);
for(Color c : color){
JButton btn = new JButton();
btn.setBackground(c);
btn.setPreferredSize(dim);
add(btn);
}
}
public void initUI(){
this.setTitle("画图板");
FlowLayout flow = new FlowLayout();
this.setLayout(flow);
this.setSize(1000,800);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(Wi
热心网友
时间:2023-10-23 20:20
第一步:创建画布
万事开头难,我们从创建一个窗体开始,并给窗体添加画笔g。
package drawBoard_test;
import javax.swing.*;
import java.awt.*;
public class DrawUI extends JFrame {
String[] strs = {"直线","签字笔","实时直线", "谢尔宾斯基地毯","递归KLine","矩形", "圆", "实心矩形", "实心圆", "等腰三角形", "三角形", "多边形",
"改进多边形","立方体", "橡皮擦", "撤回", "保存", "打开"};
Color[] color = {Color.red,Color.white,Color.black,Color.blue};
//添加功能和颜色按钮
public void addButton(){
for(String str : strs){
JButton btn = new JButton(str);
add(btn);
}
Dimension dim = new Dimension(30,30);
for(Color c : color){
JButton btn = new JButton();
btn.setBackground(c);
btn.setPreferredSize(dim);
add(btn);
}
}
public void initUI(){
this.setTitle("画图板");
FlowLayout flow = new FlowLayout();
this.setLayout(flow);
this.setSize(1000,800);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(Wi