| Constructor and Description |
|---|
GraphicsUtil() |
| Modifier and Type | Method and Description |
|---|---|
static Graphics2D |
createGraphics(BufferedImage image,
Color color)
|
static Graphics |
drawImg(Graphics g,
Image img,
Point point)
绘制图片
|
static Graphics |
drawImg(Graphics g,
Image img,
Rectangle rectangle)
绘制图片
|
static Graphics |
drawString(Graphics g,
String str,
Font font,
Color color,
int width,
int height)
绘制字符串,默认抗锯齿
|
static Graphics |
drawString(Graphics g,
String str,
Font font,
Color color,
Point point)
绘制字符串,默认抗锯齿
|
static Graphics |
drawString(Graphics g,
String str,
Font font,
Color color,
Rectangle rectangle)
绘制字符串,默认抗锯齿。
|
static Graphics |
drawStringColourful(Graphics g,
String str,
Font font,
int width,
int height)
绘制字符串,使用随机颜色,默认抗锯齿
|
static Graphics |
drawStringColourful(Graphics g,
String str,
Font font,
int width,
int height,
Color compareColor,
int minColorDistance)
绘制字符串,使用随机颜色,默认抗锯齿
|
static int |
getCenterY(Graphics g,
int backgroundHeight)
获取文字居中高度的Y坐标(距离上边距距离)
此方法依赖FontMetrics,如果获取失败,默认为背景高度的1/3 |
static Graphics2D |
setAlpha(Graphics2D g,
float alpha)
设置画笔透明度
|
public static Graphics2D createGraphics(BufferedImage image, Color color)
image - BufferedImagecolor - Color背景颜色以及当前画笔颜色,null表示不设置背景色Graphics2Dpublic static int getCenterY(Graphics g, int backgroundHeight)
g - Graphics2D画笔backgroundHeight - 背景高度public static Graphics drawStringColourful(Graphics g, String str, Font font, int width, int height)
g - Graphics画笔str - 字符串font - 字体width - 字符串总宽度height - 字符串背景高度public static Graphics drawStringColourful(Graphics g, String str, Font font, int width, int height, Color compareColor, int minColorDistance)
g - Graphics画笔str - 字符串font - 字体width - 字符串总宽度height - 字符串背景高度compareColor - 对比颜色,用于计算颜色与对比颜色的色差,色差小于minColorDistance则重新生成颜色minColorDistance - 随机生成的颜色与对比颜色的最小色差,小于此值则重新生成颜色public static Graphics drawString(Graphics g, String str, Font font, Color color, int width, int height)
g - Graphics画笔str - 字符串font - 字体color - 字体颜色,null 表示使用随机颜色(每个字符单独随机)width - 字符串总宽度height - 字符串背景的高度public static Graphics drawString(Graphics g, String str, Font font, Color color, Rectangle rectangle)
g - Graphics画笔str - 字符串font - 字体,字体大小决定了在背景中绘制的大小color - 字体颜色,null 表示使用黑色rectangle - 字符串绘制坐标和大小,此对象定义了绘制字符串的区域大小和偏移位置public static Graphics drawString(Graphics g, String str, Font font, Color color, Point point)
g - Graphics画笔str - 字符串font - 字体,字体大小决定了在背景中绘制的大小color - 字体颜色,null 表示使用黑色point - 绘制字符串的位置坐标public static Graphics drawImg(Graphics g, Image img, Point point)
g - 画笔img - 要绘制的图片point - 绘制的位置,基于左上角public static Graphics drawImg(Graphics g, Image img, Rectangle rectangle)
g - 画笔img - 要绘制的图片rectangle - 矩形对象,表示矩形区域的x,y,width,height,,基于左上角public static Graphics2D setAlpha(Graphics2D g, float alpha)
g - 画笔alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字Copyright © 2025. All rights reserved.