java生成文字与图片_java生成文字图片和文字对齐

这篇博客主要介绍了如何使用Java根据提供的文字生成jpg图片,并调整文字的位置(左对齐、右对齐、居中)。代码示例展示了如何设置背景色、字色、字体等参数,并通过main方法演示了不同对齐方式的实现。文章还提出了在全角和半角字符混合情况下如何定位的问题。
摘要由CSDN通过智能技术生成

/**

* 根据提供的文字生成jpg图片

*

* @param s

* String 文字

* @param align

* 文字位置(left,right,center)

* @param y

* y坐标

* @param width

* 图片宽度

* @param height

* 图片高度

* @param bgcolor

* Color 背景色

* @param fontcolor

* Color 字色

* @param font

* Font 字体字形字号

* @param jpgname

* String jpg图片名

* @return

*/

private static boolean createJpgByFontAndAlign(String s, String align, int y, int width, int height,

Color bgcolor, Color fontcolor, Font font, String jpgname) {

try { // 宽度 高度

BufferedImage bimage = new BufferedImage(width,

height, BufferedImage.TYPE_INT_RGB);

Graphics2D g = bimage.createGraphics();

g.setColor(bgcolor); // 背景色

g.fillRect(0, 0, width, hei

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值