写下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命令的时候可以找到字体 否则还是会出现中文乱码问题










猜你喜欢

转载自blog.csdn.net/weixin_39225655/article/details/80433433