ImageIO.write(image, “png”, new File(imageFolderPath + “春联.png”));
} catch (IOException e) {
e.printStackTrace();
}
}
//横批
public static BufferedImage writeH(String text) {
char[] ch = text.toCharArray();
BufferedImage image = new BufferedImage(640 * ch.length, 640, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
for (int i = 0; i < ch.length; i++) {
char c = ch[i];
g.drawImage(fontMark(String.valueOf©), 640 * i, 0, 640, 640, null);
}
g.dispose();
return image;
}
//上下联
public static BufferedImage writeV(String text) {
char[] ch = text.toCharArray();
BufferedImage image = new BufferedImage(2 * 640, 2 * 640 * ch.length, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
for (int i = 0; i < ch.length; i++) {
char c = ch[i];
g.drawImage(fontMark(String.valueOf©), 0, 2 * 640 * i, 2 * 640, 2 * 640, null);
}
g.dispose();
return image;
}
public static BufferedImage fontMark(String content) {
try {
BufferedImage image = ImageIO.read(new File(sourceFilePath));
return fontMark(image, content);
} catch (IOException e) {
return null;
}
}
//文字标记
public static BufferedImage fontMark(BufferedImage bufImg, String content) {
Font font = new Font(fontName, Font.BOLD, 350);
Graphics2D graphics = bufImg.createGraphics();
graphics.setColor(Color.black);
graphics.setFont(font);
graphics.drawString(content, 230, 540);
graphics.dispose();
System.out.println(content);
return bufImg;
}
}
运行main方法以后,效果图如下:
代码参考如下:
https://blog.csdn.net/weixin_40986713/article/details/122683030
感谢您的阅读,如果您感觉本篇博客还不错,请帮忙留言+点赞+收藏呗。~~
技术学习总结
学习技术一定要制定一个明确的学习路线,这样才能高效的学习,不必要做无效功,既浪费时间又得不到什么效率,大家不妨按照我这份路线来学习。
最后面试分享
大家不妨直接在牛客和力扣上多刷题,同时,我也拿了一些面试题跟大家分享,也是从一些大佬那里获得的,大家不妨多刷刷题,为金九银十冲一波!
题,同时,我也拿了一些面试题跟大家分享,也是从一些大佬那里获得的,大家不妨多刷刷题,为金九银十冲一波!
[外链图片转存中…(img-7c3Pl70C-1714339909708)]
[外链图片转存中…(img-q60dXQMP-1714339909708)]