java动态生成名片画图工具
2017-12-27 11:19
330 查看
public class ChartGraphics { private static BufferedImage image; //图片的宽度 private static final int imageWidth = 300; //图片的高度 private static final int imageHeight = 400; public static BufferedImage graphicsGenerationdoctor(String qrurl,String photo,String doctorName,String doctorTitle,String hosName) { if (null == qrurl){ qrurl = ""; } if (null == photo){ photo = ""; } if (null == doctorName){ doctorName = ""; } if (null == doctorTitle){ doctorTitle = ""; } if (null == hosName){ hosName = ""; } //头部高度 医生信息 int H_title = 100; //医生二维码高度 int H_mainPic = 300; image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); //设置图片的背景色 Graphics2D main = image.createGraphics(); main.setColor(Color.white); main.fillRect(0, 0, imageWidth, imageHeight); //医生姓名 Graphics title = image.createGraphics(); //设置区域颜色 title.setColor(Color.white); //填充区域并确定区域大小位置 title.fillRect(0, 0, imageWidth, H_title); //设置字体颜色,先设置颜色,再填充内容 title.setColor(Color.black); //设置字体 Font titleFont = new Font("宋体", Font.BOLD, 16); title.setFont(titleFont); title.drawString(doctorName, 90, (120)/2-5); //医生职称 //设置字体 这里设置职称及其下面文字的颜色,可以根据顺序设置颜色 title.setColor(Color.gray); Font titleNameFont = new Font("宋体", Font.PLAIN, 12); title.setFont(titleNameFont); title.drawString(doctorTitle, 150, (120)/2-5); //医院名称 //设置字体 Font hosNameFont = new Font("宋体", Font.PLAIN, 12); title.setFont(hosNameFont); title.drawString(hosName, 90, H_title-20); //医生头像 //设置字体 Graphics dPic = image.getGraphics(); BufferedImage dimg = null; try { dimg = javax.imageio.ImageIO.read(new URL(photo)); } catch (Exception e) {} if(dimg!=null){ dPic.setClip(new RoundRectangle2D.Double(20, 30, 60, 60, 60, 60)); dPic.drawImage(dimg, 2, 2, 90, 90, null); dPic.dispose(); } //插入二维码 Graphics mainPic = image.getGraphics(); BufferedImage bimg = null; try { bimg = javax.imageio.ImageIO.read(new URL(qrurl)); } catch (Exception e) {} if(bimg!=null){ mainPic.drawImage(bimg, 30, 100, 230, 230, null); mainPic.dispose(); } return image; } }
相关文章推荐
- Java动态生成PDF的两个开源工具-iText与FOP
- Java动态生成PDF的两个开源工具-iText与FOP
- 动态生成JAVA代码(二)
- Java爬虫Jsoup+httpclient获取动态生成的数据
- Java开发中的你,代码基本都是工具生成了吧?谁还手写
- java高仿新浪微博短链接地址生成工具ShortUrlGenerator.java
- Java 使用反射生成JDK动态代理
- java 动态代码生成。
- Java 动态生成复杂 Word
- java----代理机制或动态类的生成
- 使用java或C++,设计一个画图板(类似于windows系统自带的画图工具)。
- Java 验证码生成工具(简单实现)
- java利用zxing开源工具生成二维码QRCode
- 使用java的wsimport.exe工具生成wsdl的客户端代码
- 通过wsdl2java工具生成客户端段代码(wsdl2java -p cn.com.css.misps.graph.webservice.impl -d F:\src -all http://10.)
- Java调用ffmpeg工具生成视频缩略图实例
- 利用Java反射机制和Javassist实现Java对象及其属性的动态创建生成
- 使用Java程序片段动态生成表格
- 基于Java模板技术动态生成Word文档
- Java应用iText动态生成PDF文件-温柔一刀