java动态生成名片画图工具

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;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值