写下java后台手工画图的方法


import java.awt.Color;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;


import javax.imageio.ImageIO;


public class ChartUtil {

public static BufferedImage getTextPicAndQrcode(String url,String customname,String num,String unit,String cny,String content,String picpng) throws IOException{ 

InputStream inputStream=QrcodeSpiderWebPlotUtil.class.getResourceAsStream("/resource/chart/bg.png");
BufferedImage bgImg = ImageIO.read(inputStream);

Color FONTCOLOR=new Color(0xEBD9A0);
Color YELLOWCOLOR=new Color(0xFFE71A);
Font NORMALFONT=new Font(null,Font.BOLD,24);
Font BIGFONT=new Font(null,Font.PLAIN,48);
Font BIGERFONT=new Font(null,Font.PLAIN,60);
//Font MOSTBIGERFONT=new Font("MicrosoftYaHei Regular",Font.PLAIN,65);
//Font MOSTBIGERFONT=new Font("微软雅黑",Font.PLAIN,65);
Font MOSTBIGERFONT=new Font(null,Font.PLAIN,65);
//第一行
StringLine line=new StringLine();
List<StringElement> list=new ArrayList<>();


StringElement e=new StringElement(customname,FONTCOLOR,BIGFONT);
list.add(e);

line.setList(list);
line.setX(60+72);
line.setY(295);
List<StringEntity> strs=QrcodeSpiderWebPlotUtil.getStringLine(line);

//第二行
line=new StringLine();
list=new ArrayList<>();

e=new StringElement(num,YELLOWCOLOR,MOSTBIGERFONT);
e.setAdjustlength(getAdjustLength(num));
list.add(e);


e=new StringElement(unit,YELLOWCOLOR,MOSTBIGERFONT);
list.add(e);

e=new StringElement(cny,FONTCOLOR,NORMALFONT);
list.add(e);

line.setList(list);
line.setX(60+207);
line.setY(383);
strs.addAll(QrcodeSpiderWebPlotUtil.getStringLine(line));

//第三行
line=new StringLine();
list=new ArrayList<>();


e=new StringElement(content,YELLOWCOLOR,BIGERFONT);
list.add(e);

line.setList(list);
line.setX(60+250);
line.setY(470);
strs.addAll(QrcodeSpiderWebPlotUtil.getStringLine(line));
//

InputStream picinputStream=QrcodeSpiderWebPlotUtil.class.getResourceAsStream("/resource/chart/"+picpng);
BufferedImage pic = ImageIO.read(picinputStream);
PicEntity picEntity = new PicEntity();
picEntity.setX(0);
picEntity.setY(530);
picEntity.setPic(pic);

//

QrcodeEntity qrcodeEntity=new QrcodeEntity();
qrcodeEntity.setContent(url);
//int YELLOW = 0xFF743018;
//int NOCOLOR = 0x000000;
int BGCOLOR=0xFFebd9a0;
int FRONTCOLOR=0xFF3b3029;
qrcodeEntity.setFrontColor(FRONTCOLOR);
qrcodeEntity.setBgColor(BGCOLOR);
qrcodeEntity.setX(80);
qrcodeEntity.setY(1100);
qrcodeEntity.setCode_width(140);
//qrcodeEntity.setFrontColor(YELLOW);

BufferedImage ret=QrcodeSpiderWebPlotUtil.getTextPicAndQrcode(bgImg,strs,qrcodeEntity,picEntity);
return ret;
}

private static int getAdjustLength(String str) {
return str.length()*25;
}

 

 

 

}

 

 

 

 

注意要看自己公司的实际情况 因为这边用到了  宋体 如果在服务器上没有安装字体会出现中文乱码  

注意  要是你们公司也是用docker 那么你要重新配置你的镜像 让你执行docker命令的时候可以找到字体 否则还是会出现中文乱码问题

 

 

 

 

 

 

 

 

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值