| | |
| | | public byte[] generateBarcodeImage(String barcodeText) { |
| | | try { |
| | | // 使用 BitMatrix 生成纯条码,不包含任何文字 |
| | | BarcodeFormat format = BarcodeFormat.CODE_128; // 根据您的条码类型 |
| | | BarcodeFormat format = BarcodeFormat.CODE_39; // 根据您的条码类型 |
| | | |
| | | // 创建编码器 |
| | | Code128Writer writer = new Code128Writer(); |
| | | Code39Writer writer = new Code39Writer(); |
| | | |
| | | // 编码参数 |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.MARGIN, 0); // 无边框 |
| | | |
| | | // 生成 BitMatrix(纯条码,无文字) |
| | | BitMatrix matrix = writer.encode(barcodeText, format, 0, 63, hints); |
| | | BitMatrix matrix = writer.encode(barcodeText, format, 230, 63, hints); |
| | | |
| | | int width = matrix.getWidth(); |
| | | int height = matrix.getHeight(); |
| | |
| | | g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); |
| | | g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); |
| | | |
| | | Font font = new Font("Tahoma", Font.PLAIN, 20); |
| | | Font font = new Font("Tahoma", Font.PLAIN, 18); |
| | | g2d.setFont(font); |
| | | |
| | | FontMetrics fm = g2d.getFontMetrics(); |
| | |
| | | g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); |
| | | g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); |
| | | |
| | | Font font = new Font("Tahoma", Font.PLAIN, 20); |
| | | Font font = new Font("Tahoma", Font.PLAIN, 18); |
| | | g2d.setFont(font); |
| | | |
| | | FontMetrics fm = g2d.getFontMetrics(); |