public class CreateImage {
public static void main(String[] args) throws Exception{
int width = 100;
int height = 100;
String s = "你好"; File file = new File("/Users/tengxin/Pictures/image.jpg"); Font font = new Font("Serif", Font.BOLD, 10);
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D)bi.getGraphics();
g2.setBackground(Color.WHITE);
g2.clearRect(0, 0, width, height);
g2.setPaint(Color.RED); FontRenderContext context = g2.getFontRenderContext();
Rectangle2D bounds = font.getStringBounds(s, context);
double x = (width - bounds.getWidth()) / 2;
double y = (height - bounds.getHeight()) / 2;
double ascent = -bounds.getY();
double baseY = y + ascent; g2.drawString(s, (int)x, (int)baseY); ImageIO.write(bi, "jpg", file);
}
}

最新文章

  1. centos,nginx安装备忘
  2. JDBC中的PreparedStatement
  3. docker进入容器方法
  4. Centos yum install
  5. 使用(Drawable)资源——图片资源
  6. 浅谈数据结构vector
  7. 微信跳转ticket值怎么得到?浏览器跳到微信?哪里有微信跳转接口?跳转功能能用多久?
  8. Ubuntu下创建XFS文件系统的LVM
  9. Hadoop开启后jps显示只有jps
  10. java中LIst转换成Json
  11. 洛谷P5162 WD与积木 [DP,NTT]
  12. idea 自动换行
  13. MYSQLi数据访问查询数据
  14. Hash 迭代程序构造器要求字符串参数--错误解决
  15. Codeforces Beta Round #67 (Div. 2)
  16. 使用spring单元调试出错initializationError
  17. 测试word发表博客
  18. java-mybaits-011-mybatis-拦截器计算耗时
  19. 【转】python基础-编码与解码
  20. 2018年UI设计趋势概览

热门文章

  1. go-swagger的简单使用
  2. RabbitMQ安装后,BADARG问题
  3. 编写linux 命令行实用工具 shell命令
  4. HBase的集群搭建(1、3、5节点都适用)
  5. 机器学习:随机森林RF-OBB袋外错误率
  6. python write和writelines的区别
  7. JavaEE的起步
  8. 【转】虚拟化(一):虚拟化及vmware产品介绍
  9. MySQL NULL 值如何处理?
  10. markdown让文字居中和带颜色