提交 93780d1c authored 作者: 黄承天's avatar 黄承天

尺寸调整

上级 df6d5c60
......@@ -12,7 +12,7 @@ import java.io.IOException;
*/
public class DrawImageUtil {
private static Integer width = 400;
private static Integer width = 300;
private static Integer height = 200;
......@@ -31,10 +31,10 @@ public class DrawImageUtil {
//留白率 例如40就是留白1/40
int blankRange = 40;
//计算条形码尺寸
Integer barCodeWidth = width - (width / blankRange) * 2;
Integer barCodeHeight = (height - offsetY) / 5;
Integer barCodeWidth = width - (width / blankRange) * 2;//320
Integer barCodeHeight = (height - offsetY) / 5;//32
//计算字体尺寸
int fontSize = Math.min(((height - offsetY) / 2) / 3, (width - width / blankRange - offsetX) / maxLength(string1, string2, string3));
int fontSize = Math.min(((height - offsetY) / 5), (width - width / blankRange - offsetX) / maxLength(string1, string2, string3));
graphics.setFont(new Font("Default", Font.BOLD, fontSize));
//写入条形码
graphics.drawImage(BarCodeUtil.createBarCodeImg(String.valueOf(id), barCodeWidth, barCodeHeight), null, width / blankRange, offsetY + height / blankRange);
......
package com.example.printer;
import java.awt.image.BufferedImage;
import java.io.File;
import static java.lang.String.format;
public class Test {
public static void main(String[] args) {
BufferedImage bufferedImage = DrawImageUtil.drawImage(1, "123", "123", "123");
DrawImageUtil.writeImage(bufferedImage,System.getProperty("user.dir")+File.separator+"test.png");
PrinterUtil.execute(Image2Zpl.image2Zpl(bufferedImage));
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论