| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 | | 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); |  |     } |  | } | 
 |