利用barcode4j生成条形码详解编程语言

  
package k.barcode; 
   
import java.awt.image.BufferedImage; 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.OutputStream; 
   
import org.krysalis.barcode4j.impl.code39.Code39Bean; 
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; 
import org.krysalis.barcode4j.tools.UnitConv; 
   
public class Barcode { 
   
    public static void main(String[] args) { 
        try { 
            //Create the barcode bean 
            Code39Bean bean = new Code39Bean(); 
               
            final int dpi = 150; 
               
            //Configure the barcode generator 
            bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar  
                                                             //width exactly one pixel 
            bean.setWideFactor(3); 
            bean.doQuietZone(false); 
               
            //Open output file 
            File outputFile = new File("d:////out.png"); 
            OutputStream out = new FileOutputStream(outputFile); 
            try { 
                //Set up the canvas provider for monochrome JPEG output  
                BitmapCanvasProvider canvas = new BitmapCanvasProvider( 
                        out, "image/png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0); 
               
                //Generate the barcode 
                bean.generateBarcode(canvas, "A123456"); 
               
                //Signal end of generation 
                canvas.finish(); 
            } finally { 
                out.close(); 
            } 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    } 
   
} 
  

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/10638.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论