代码拉取完成,页面将自动刷新
package com.xiaobai.itextpdf;
import org.apache.poi.util.IOUtils;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.*;
/**
* @author wangtw
* @ClassName ImageUtil
* @description: 图片工具类
* @date 2024/1/1620:36
*/
public class ImageUtil {
/**
* 生成带文字的图片
* @return
*/
public static String createImage() {
int imageWidth = 80;
int imageHeight = 30;
BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
Color c = new Color(255, 255, 255);
g2.setColor(c);// 设置背景色
g2.fillRect(0, 0, imageWidth, imageHeight);
String code = "000153";
// 设置文字字体
Font font = new Font(null, Font.PLAIN, 10);
g2.setFont(font);
g2.setColor(new Color(0, 0, 0));
// 文字起始位置
g2.drawString(code, 5, 15);
g2.dispose();
String imagePath = "D:\\usr\\local\\zeus\\resource\\temp/aaa.jpg";
OutputStream baos = null;
try {
baos = new FileOutputStream(new File(imagePath));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
ImageIO.write(image, "jpg", baos);
} catch (IOException e) {
e.printStackTrace();
}
// 关闭输出流
IOUtils.closeQuietly(baos);
return imagePath;
}
public static void main(String[] args) {
createImage();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。