| | |
| | | public byte[] generateBarcodeImage(String barcodeText) { |
| | | try { |
| | | // 使用 BitMatrix 生成纯条码,不包含任何文字 |
| | | BarcodeFormat format = BarcodeFormat.CODE_39; // 根据您的条码类型 |
| | | BarcodeFormat format = BarcodeFormat.CODE_128; // 根据您的条码类型 |
| | | |
| | | // 创建编码器 |
| | | Code39Writer writer = new Code39Writer(); |
| | | Code128Writer writer = new Code128Writer(); |
| | | |
| | | // 编码参数 |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | |
| | | } |
| | | |
| | | // 添加自定义文字 |
| | | g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, |
| | | RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
| | | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| | | g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
| | | 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.BOLD, 18); |
| | | Font font = new Font("Tahoma", Font.PLAIN, 20); |
| | | g2d.setFont(font); |
| | | |
| | | FontMetrics fm = g2d.getFontMetrics(); |