package com.dy.common.util; import java.awt.*; import java.awt.image.BufferedImage; public class GraphicsUtils { // 创建一个空白的 BufferedImage 对象 public static BufferedImage createEmptyImage(int width, int height) { return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); } // 在图像上设置背景颜色 public static void drawBackground(Graphics2D g2d,int x, int y, int width, int height, Color color) { g2d.setBackground(color); g2d.clearRect(x, y, width, height); } // 在图像上绘制文本 public static void drawText(Graphics2D g2d, String text, int x, int y, Font font, Color color) { g2d.setColor(color); g2d.setFont(font); g2d.drawString(text, x, y); } // 在图像上绘制矩形 public static void drawRectangle(Graphics2D g2d, int x, int y, int width, int height, Color color) { g2d.setColor(color); g2d.drawRect(x, y, width, height); } // 在图像上绘制椭圆 public static void drawEllipse(Graphics2D g2d, int x, int y, int width, int height, Color color) { g2d.setColor(color); g2d.drawOval(x, y, width, height); } // 在图像上绘制线段 public static void drawLine(Graphics2D g2d, int x1, int y1, int x2, int y2, Color color) { g2d.setColor(color); g2d.drawLine(x1, y1, x2, y2); } // 在图像上绘制图片 public static void drawImage(Graphics2D g2d, BufferedImage imageToDraw, int x, int y) { g2d.drawImage(imageToDraw, x, y, null); } // 在图像指定区域绘制颜色 public static void drawFillRect(Graphics2D g2d, int x, int y, int width, int height, Color color) { g2d.setColor(color); g2d.fillRect(x, y, width, height); } // 在图像指定区域绘制颜色 public static void drawFont(Graphics2D g2d,Font font, Color color) { g2d.setFont(font); g2d.setColor(color); } }