Java语言画图
package cn.witksy.dev; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; /** * Author: Alfred * Created: 2015/5/7 */ public class Main { public void run() { BufferedImage bufferedImage = new BufferedImage(100,50,BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bufferedImage.createGraphics(); g2.setColor(Color.red); g2.fillRect(0,0,5,5); g2.setColor(Color.blue); g2.fillRect(10,20,5,5); File outputFile = new File("D:\\dev\\java\\workspace\\draw2dtest\\test.png"); try { ImageIO.write(bufferedImage, "png", outputFile); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { new Main().run(); } }
时间: 2024-11-05 22:43:57