Java生成条形码code128
前言
(51条消息) Java生成条形码code128_明明如月学长的博客-CSDN博客_code128bean怎么谁知两侧留白
1 public class BarcodeUtil { 2 3 4 public static File generateFile(String msg, String path) { 5 File file = new File(path); 6 try { 7 generate(msg, new FileOutputStream(file)); 8 } catch (FileNotFoundException e) { 9 throw new RuntimeException(e); 10 } 11 return file; 12 } 13 14 15 public static byte[] generate(String msg) { 16 ByteArrayOutputStream ous = new ByteArrayOutputStream(); 17 generate(msg, ous); 18 return ous.toByteArray(); 19 } 20 public static void generate(String msg, OutputStream ous) { 21 if (StringUtils.isEmpty(msg) || ous == null) { 22 return; 23 } 24 25 Code128Bean bean = new Code128Bean(); 26 final int dpi = 512; 27 final double moduleWidth = UnitConv.in2mm(2.0f / dpi); 28 bean.setModuleWidth(moduleWidth); 29 bean.setHeight(30); 30 bean.doQuietZone(false); 31 HumanReadablePlacement none = HumanReadablePlacement.byName("none"); 32 bean.setMsgPosition(none); 33 34 String format = "image/png"; 35 try { 36 37 BitmapCanvasProvider canvas = new BitmapCanvasProvider(ous, format, dpi, 38 BufferedImage.TYPE_BYTE_BINARY, false, 0); 39 bean.generateBarcode(canvas, msg); 40 41 canvas.finish(); 42 } catch (IOException e) { 43 throw new RuntimeException(e); 44 } 45 } 46 47 48 49 }
本文来自博客园,作者:chch213,转载请注明原文链接:https://www.cnblogs.com/chch213/p/17076138.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探
2018-01-30 mysql数据库学习小结