把文字生成图片
来源:互联网 发布:布雷克.格里芬数据 编辑:程序博客网 时间:2024/05/16 23:54
package cn.com.bmsoft.util;import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.awt.image.BufferedImage;import java.io.BufferedOutputStream;import java.io.FileOutputStream;import com.sun.image.codec.jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPEGImageEncoder;/** * 把文字生成图片 * @author lizhiyong * @version $Id: ChartGraphics.java, v 0.12015-6-3 下午3:20:59 1111 Exp $ */public class ChartGraphics { BufferedImage image; /** * 生成图片 * @param fileLocation 图片存放路径 */ void createImage(String fileLocation) { try { FileOutputStream fos = new FileOutputStream(fileLocation); BufferedOutputStream bos = new BufferedOutputStream(fos); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos); encoder.encode(image); bos.close(); } catch (Exception e) { e.printStackTrace(); } } /** * 把文字生成图片 * @param name 图片上的文字 * @param id * @param classname * @param imgurl */ public void graphicsGeneration(String imageFont, String imgPath) { int imageWidth = 450;// 图片的宽度 int imageHeight = 500;// 图片的高度 image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); Graphics graphics = image.getGraphics(); graphics.setColor(Color.WHITE); graphics.fillRect(0, 0, imageWidth, imageHeight); graphics.setColor(Color.BLACK); graphics.setFont(new Font("宋体", Font.BOLD, 10)); graphics.drawString(imageFont, 50, 20); // 改成这样: BufferedImage bimg = null; try { bimg = javax.imageio.ImageIO.read(new java.io.File(imgPath)); } catch (Exception e) { } if (bimg != null) graphics.drawImage(bimg, 50, 0, null); graphics.dispose(); createImage(imgPath); } public static void main(String[] args) { ChartGraphics cg = new ChartGraphics(); try { cg.graphicsGeneration("ewew", "\\ploanshare\\2\\11.jpg"); } catch (Exception e) { e.printStackTrace(); } }}
0 0
- 把文字生成图片
- Android把文字写到图片上生成图片+文字的新图片
- 文字生成图片
- java生成图片文字
- 文字生成图片
- 文字生成图片
- c# 生成文字图片
- 生成中奖文字图片
- java 生成文字图片
- java文字生成图片
- java 文字生成图片
- java 文字生成图片
- 把文字图片转换成文本文字
- ASP.net生成文字图片
- ASP.net生成文字图片
- ASP.net生成文字图片
- ASP.net生成文字图片
- 动态生成文字图片解决方案
- java实现把两张图片合并
- main_activiy cannot be resolved or is not a field
- Unity3D帮助文档跳转缓慢----Vim编辑器批量替换文件内容
- 唐山陶瓷造型设计,唐山陶瓷造型模具
- leetcode--Excel Sheet Column Title
- 把文字生成图片
- Tomcat java VM配置参数
- 解密系列(系统篇_PE结构详解笔记3)
- 生成pdf文件
- YTU 2509: 奇怪的分式
- c语言中用括号将花括号括起来给变量赋值
- Git经验总结
- ubuntu备份与恢复
- hadoop学习笔记(四)——eclipse+maven+hadoop2.5.2源码