您的位置:首页 > 编程语言 > Java开发

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 图片 名片