我看到你提问了java生成条形码的问题,请问你是用什么生成的?我现在也有这个问题
发布网友
发布时间:2022-04-25 19:43
我来回答
共1个回答
热心网友
时间:2023-10-14 16:28
public static final int height = 226 + 2 * border; // 8cm + border
public static final int width = 212 + 2 * border; // 7.5cm + border
private static final int rate = 3; // 条码宽条与窄条宽度之比
private static int m_nNarrowWidth = 10; // 窄条的宽度像素数
private static int m_nImageHeight = 250; // 条码的高度像素数
// =========添加条形码begin===================
Barcode128 barcode128 = new Barcode128();
String strCodes = shipment.getPostalReferenceNo();
barcode128.setCode(strCodes);
int nImageWidth = (strCodes.length() * (3 * rate + 7) * m_nNarrowWidth);
java.awt.image.BufferedImage bufferedImage = new BufferedImage(
nImageWidth, m_nImageHeight + 13, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
g.fillRect(0, 33, nImageWidth, 13);
java.awt.Image codeImg = barcode128.createAwtImage(Color.black,
Color.white);
g.drawImage(codeImg, 0, 0, nImageWidth, m_nImageHeight, null);
g.setColor(Color.BLUE);
g.dispose();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "jpg", os);
Image img1 = Image.getInstance(os.toByteArray());
img1.setAlignment(Image.ALIGN_CENTER);
你试试来自:求助得到的回答