Commit bb661b08 by 裴大威

调整条形码文字大小

parent f2092b6c
......@@ -114,14 +114,14 @@ public class CopyrightTools {
String zipFilePath = ZIP_FILE_PATH + tempZipName + ".zip";
String fileFolderPath = FILE_LOCAL_PATH + tempZipName;
FileUtils.isDir(fileFolderPath);
UploadResultInfo uploadResultInfo = null;
UploadResultInfo uploadResultInfo;
try {
for (BookAuthCode bookAuthCode : bookAuthCodes) {
BufferedImage bi = null;
BufferedImage bi;
JBarcode productBarcode = new JBarcode(Code128Encoder.getInstance(), WidthCodedPainter.getInstance(), EAN13TextPainter.getInstance());
productBarcode.setXDimension(Double.valueOf(0.5));
productBarcode.setBarHeight(Double.valueOf(30));
productBarcode.setWideRatio(Double.valueOf(30.0D));
productBarcode.setXDimension(0.5);
productBarcode.setBarHeight(30d);
productBarcode.setWideRatio(30.0D);
productBarcode.setShowText(true);
productBarcode.setTextPainter(BaseLineTextPainter.getInstance());
bi = productBarcode.createBarcode(bookAuthCode.getFullCode());
......@@ -190,20 +190,42 @@ public class CopyrightTools {
}
return last6Months;
}
// public static void paintText(BufferedImage barCodeImage, String text) {
// //绘图
// Graphics g2d = barCodeImage.getGraphics();
// //创建字体
// Font font = new Font("console", Font.PLAIN, 15 );
// g2d.setFont(font);
// FontMetrics fm = g2d.getFontMetrics();
// int height = fm.getHeight();
// int center = (barCodeImage.getWidth() - fm.stringWidth(text)) / 2;
// g2d.setColor(Color.WHITE);
// g2d.fillRect(0, 0, barCodeImage.getWidth(), barCodeImage.getHeight() * 1 / 20);
// g2d.fillRect(0, barCodeImage.getHeight() - (height * 9 / 10), barCodeImage.getWidth(), (height * 9 / 10));
// g2d.setColor(Color.BLACK);
// g2d.drawString(text, center, barCodeImage.getHeight() - (height / 10) - 2);
// }
public static void paintText(BufferedImage barCodeImage, String text) {
//绘图
Graphics g2d = barCodeImage.getGraphics();
//创建字体
Font font = new Font("console", Font.PLAIN, 15 );
Font font = new Font("console", Font.PLAIN, 25);
g2d.setFont(font);
FontMetrics fm = g2d.getFontMetrics();
int height = fm.getHeight();
int center = (barCodeImage.getWidth() - fm.stringWidth(text)) / 2;
// int center = (barCodeImage.getWidth() - fm.stringWidth(text)) / 2;
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, barCodeImage.getWidth(), barCodeImage.getHeight() * 1 / 20);
g2d.fillRect(0, 0, barCodeImage.getWidth(), barCodeImage.getHeight() / 20);
g2d.fillRect(0, barCodeImage.getHeight() - (height * 9 / 10), barCodeImage.getWidth(), (height * 9 / 10));
g2d.setColor(Color.BLACK);
g2d.drawString(text, center, barCodeImage.getHeight() - (height / 10) - 2);
//g2d.drawString(text, center, barCodeImage.getHeight() - (height / 10) - 2);
int start = 17;
int length = (barCodeImage.getWidth() - 2 * start) / text.length();
for (int i = 0; i < text.length(); i++) {
g2d.drawString(text.substring(i, i + 1), start + i * length, barCodeImage.getHeight() - (height / 10) - 2);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment