|
@@ -5,12 +5,13 @@ import com.github.zuihou.common.util.DateUtil;
|
|
|
import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.util.Date;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
public class ImageProducerUtil {
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
- new ImageProducerUtil().createImage("");
|
|
|
+ // new ImageProducerUtil().createImage("");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -30,64 +31,48 @@ public class ImageProducerUtil {
|
|
|
*
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public static BufferedImage createImage(String unqueCode) throws Exception {
|
|
|
+ public static BufferedImage createImage(Map<String,String> map) throws Exception {
|
|
|
|
|
|
Font font1 = new Font("黑体", Font.BOLD, 36);//标题字体
|
|
|
- Font font2 = new Font("宋体", Font.BOLD, 28);//内容字体
|
|
|
- Font font3 = new Font("宋体", Font.BOLD, 16);//编号字体
|
|
|
+ Font font2 = new Font("宋体", Font.BOLD, 25);//内容字体
|
|
|
+ Font font3 = new Font("宋体", Font.BOLD, 20);//编号字体
|
|
|
|
|
|
// 创建图片
|
|
|
- BufferedImage image = new BufferedImage(480, 320, BufferedImage.TYPE_INT_BGR);// 创建图片画布
|
|
|
+ BufferedImage image = new BufferedImage(480, 640, BufferedImage.TYPE_INT_BGR);// 创建图片画布
|
|
|
Graphics g = image.getGraphics();
|
|
|
g.setColor(Color.WHITE); // 先用白色填充整张图片,也就是背景
|
|
|
- g.fillRect(0, 0, 480, 320);// 画出矩形区域,以便于在矩形区域内写入文字
|
|
|
+ g.fillRect(0, 0, 480, 640);// 画出矩形区域,以便于在矩形区域内写入文字
|
|
|
g.setColor(Color.black);// 再换成黑色,以便于写入文字
|
|
|
- //g.setFont(font1);// 设置画笔字体
|
|
|
-// g.drawString("样品标识", 120, 42);// 画出一行字符串
|
|
|
+ g.setFont(font2);
|
|
|
+ g.drawString("零件名称:", 60, 70);
|
|
|
g.setFont(font3);
|
|
|
- g.drawString("产品名称:", 3, 74);
|
|
|
+ g.drawString(map.get("bomName"), 200, 70);
|
|
|
+ g.setFont(font2);
|
|
|
+ g.drawString("当前工序:", 60, 110);
|
|
|
g.setFont(font3);
|
|
|
- g.drawString("前格框", 3, 116);
|
|
|
+ g.drawString(map.get("procedureName"), 200, 110);
|
|
|
+ g.setFont(font2);
|
|
|
+ g.drawString("炉批号:", 60, 150);
|
|
|
g.setFont(font3);
|
|
|
- g.drawString("生产日期:", 3, 158);
|
|
|
+ g.drawString(map.get("furnaceBatchNo"), 200, 150);
|
|
|
+ g.setFont(font2);
|
|
|
+ g.drawString( "交货日期:", 60, 190);
|
|
|
g.setFont(font3);
|
|
|
- g.drawString( DateUtil.formatTimeByStrFormat("yyyy-MM-dd HH:mm:ss", new Date()), 3, 200);
|
|
|
+ g.drawString( map.get("deliveryTime"), 200, 190);
|
|
|
+ g.setFont(font2);
|
|
|
+ g.drawString( "订单名称:", 60, 230);
|
|
|
g.setFont(font3);
|
|
|
- g.drawString("云箭集团", 3, 242);
|
|
|
-
|
|
|
- //二维码
|
|
|
- TwoDimensionCode handler = new TwoDimensionCode();
|
|
|
- BufferedImage codeImg = handler.encoderQRCode(unqueCode, "png", 11);
|
|
|
- g.drawImage(codeImg, 210, 60, codeImg.getWidth(), codeImg.getHeight(), null);
|
|
|
-
|
|
|
- g.dispose();
|
|
|
-
|
|
|
- return image;
|
|
|
- }
|
|
|
-
|
|
|
- public static BufferedImage createImage1() throws Exception {
|
|
|
-
|
|
|
- Font font1 = new Font("黑体", Font.BOLD, 36);//标题字体
|
|
|
- Font font2 = new Font("宋体", Font.BOLD, 10);//内容字体
|
|
|
- Font font3 = new Font("宋体", Font.BOLD, 24);//编号字体
|
|
|
-
|
|
|
- int w = 700, h = 350;
|
|
|
- // 创建图片
|
|
|
- BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);// 创建图片画布
|
|
|
- Graphics g = image.getGraphics();
|
|
|
- g.setColor(Color.WHITE); // 先用白色填充整张图片,也就是背景
|
|
|
- g.fillRect(0, 0, w, h);// 画出矩形区域,以便于在矩形区域内写入文字
|
|
|
- g.setColor(Color.black);// 再换成黑色,以便于写入文字
|
|
|
- g.setFont(font1);// 设置画笔字体
|
|
|
- g.drawString("商品名称1234,,,,,,,,,,()()", 10, 30);// 画出一行字符串
|
|
|
+ g.drawString( map.get("orderName"), 200, 230);
|
|
|
g.setFont(font2);
|
|
|
-
|
|
|
+ g.drawString("打码时间:", 60, 270);
|
|
|
+ g.setFont(font3);
|
|
|
+ g.drawString(DateUtil.dateToString0(new Date(),"yyyy-MM-dd HH:mm"), 200, 270);
|
|
|
|
|
|
//二维码
|
|
|
TwoDimensionCode handler = new TwoDimensionCode();
|
|
|
- String encoderContentStr = "样品编号:TX2-18/03/29-003-123456-123\n委托编号:CEPR1-TX2-2018-130-1234567";
|
|
|
- BufferedImage codeImg = handler.encoderQRCode(encoderContentStr, "png", 9);
|
|
|
- g.drawImage(codeImg, 40, 50, codeImg.getWidth(), codeImg.getHeight(), null);
|
|
|
+ BufferedImage codeImg = handler.encoderQRCode(map.get("uniqueCode"), "png", 15);
|
|
|
+ g.drawImage(codeImg, 110, 310, codeImg.getWidth(), codeImg.getHeight(), null);
|
|
|
+
|
|
|
g.dispose();
|
|
|
|
|
|
return image;
|