Java 生產條碼代碼

來源:互聯網
上載者:User

標籤:條碼   java   

第一種方法:

public String getJbarcode(String barCode){

String barCodePath = "";

        try {  

            JBarcode localJBarcode = new JBarcode(EAN13Encoder.getInstance(),WidthCodedPainter.getInstance(),EAN13TextPainter.getInstance());  

            BufferedImage localBufferedImage = localJBarcode.createBarcode(barCode);  

             

            saveToJPEG(localBufferedImage, barCode+".jpg");

        }  

        catch (Exception localException) {  

            localException.printStackTrace();  

        }  

        return barCodePath;

}

 

    static void saveToJPEG(BufferedImage paramBufferedImage, String paramString) {  

        saveToFile(paramBufferedImage, paramString, "jpeg");  

    }  

 

    static void saveToFile(BufferedImage paramBufferedImage, String paramString1, String paramString2) {  

        try {  

            FileOutputStream localFileOutputStream = new FileOutputStream("/Users/mac/user/" + paramString1);  

            ImageUtil.encodeAndWrite(paramBufferedImage, paramString2, localFileOutputStream, 96, 96);  

            localFileOutputStream.close();  

        }  

        catch (Exception localException) {  

            localException.printStackTrace();  

        }  

    } 





第二種方法:

 public static void main(String[] paramArrayOfString)  

  {  

    try  

    {  

      JBarcode localJBarcode = new JBarcode(EAN13Encoder.getInstance(), WidthCodedPainter.getInstance(), EAN13TextPainter.getInstance());  

      //產生. 歐洲商品條碼(=European Article Number)  

      //這裡我們用作圖書條碼  

      String str = "693320970002";  

      BufferedImage localBufferedImage = localJBarcode.createBarcode(str);  

      saveToGIF(localBufferedImage, "EAN13.gif");  

      localJBarcode.setEncoder(Code39Encoder.getInstance());  

      localJBarcode.setPainter(WideRatioCodedPainter.getInstance());  

      localJBarcode.setTextPainter(BaseLineTextPainter.getInstance());  

      localJBarcode.setShowCheckDigit(false);  

      //xx  

      str = "JBARCODE-39";  

      localBufferedImage = localJBarcode.createBarcode(str);  

      saveToPNG(localBufferedImage, "Code39.png");  

 

    }  

    catch (Exception localException)  

    {  

      localException.printStackTrace();  

    }  

  }  

 

  static void saveToJPEG(BufferedImage paramBufferedImage, String paramString)  

  {  

    saveToFile(paramBufferedImage, paramString, "jpeg");  

  }  

 

  static void saveToPNG(BufferedImage paramBufferedImage, String paramString)  

  {  

    saveToFile(paramBufferedImage, paramString, "png");  

  }  

 

  static void saveToGIF(BufferedImage paramBufferedImage, String paramString)  

  {  

    saveToFile(paramBufferedImage, paramString, "gif");  

  }  

 

  static void saveToFile(BufferedImage paramBufferedImage, String paramString1, String paramString2)  

  {  

    try  

    {  

      FileOutputStream localFileOutputStream = new FileOutputStream("/Users/mac/user" + paramString1);  

      ImageUtil.encodeAndWrite(paramBufferedImage, paramString2, localFileOutputStream, 96, 96);  

      localFileOutputStream.close();  

    }  

    catch (Exception localException)  

    {  

      localException.printStackTrace();  

    }  

  }  


本文出自 “12344888” 部落格,請務必保留此出處http://12354888.blog.51cto.com/12344888/1877899

Java 生產條碼代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.