[Java]代码
01 | /* |
02 | 2. * To change this template, choose Tools | Templates |
03 | 3. * and open the template in the editor. |
04 | 4. */ |
05 | |
06 | package com.zhilong.juyuansu.test; |
07 | |
08 | import java.awt.image.BufferedImage; |
09 | import java.io.FileOutputStream; |
10 | import org.jbarcode.JBarcode; |
11 | import org.jbarcode.encode.EAN8Encoder; |
12 | import org.jbarcode.paint.EAN8TextPainter; |
13 | import org.jbarcode.paint.WidthCodedPainter; |
14 | import org.jbarcode.util.ImageUtil; |
15 | /** |
16 | * 2012-05-28 |
17 | * @author 郏高阳 |
18 | * 支持EAN13, EAN8, UPCA, UPCE, Code 3 of 9, Codabar, Code 11, Code 93, Code 128, MSI/Plessey, Interleaved 2 of PostNet等 |
19 | * 利用jbarcode生成各种条形码!测试成功!分享给大家! |
20 | */ |
21 | public class OneBarcodeUtil { |
22 | |
23 | public static void main(String[] paramArrayOfString) { |
24 | try { |
25 | JBarcode localJBarcode = new JBarcode(EAN8Encoder.getInstance(),WidthCodedPainter.getInstance(),EAN8TextPainter.getInstance()); |
26 | String str = "2219644" ; |
27 | BufferedImage localBufferedImage = localJBarcode.createBarcode(str); |
28 | |
29 | saveToGIF(localBufferedImage, "EAN8.jpg" ); |
30 | } |
31 | catch (Exception localException) { |
32 | localException.printStackTrace(); |
33 | } |
34 | } |
35 | |
36 | static void saveToJPEG(BufferedImage paramBufferedImage, String paramString) { |
37 | saveToFile(paramBufferedImage, paramString, "jpeg" ); |
38 | } |
39 | |
40 | static void saveToFile(BufferedImage paramBufferedImage, String paramString1, String paramString2) { |
41 | try { |
42 | FileOutputStream localFileOutputStream = new FileOutputStream( "C:\\Users\\Administrator\\Desktop/" + paramString1); |
43 | ImageUtil.encodeAndWrite(paramBufferedImage, paramString2, localFileOutputStream, 96 , 96 ); |
44 | localFileOutputStream.close(); |
45 | } |
46 | catch (Exception localException) { |
47 | localException.printStackTrace(); |
48 | } |
49 | } |
50 | } |