大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
一个比较好的2d条形码解析条码的工具库
公司主营业务:网站建设、成都做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出朔州免费做网站回馈大家。
从ZXING 中剥离出来的
测试了一下,还可以,基本上清晰图片都可以识别
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.image.BufferedImage;
import com.google.zxing.MonochromeBitmapSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Reader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageMonochromeBitmapSource;
public class CodeReader {
/**
* @param args
* @throws ReaderException
* @throws InterruptedException
*/
public static void main(String[] args) throws ReaderException, InterruptedException {
Reader reader = new MultiFormatReader();
String imgPath =
"test.jpg";
Image image=java.awt.Toolkit.getDefaultToolkit().getImage(imgPath);
BufferedImage myImage = CodeReader.imageToBufImage(image);
MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(myImage);
Result result = reader.decode(source);
System.out.println(result.getText());
}
public static BufferedImage imageToBufImage(Image image) throws InterruptedException{
MediaTracker mt=new MediaTracker(new Frame());
mt.addImage(image,0);
mt.waitForID(0);
BufferedImage bufImage=new BufferedImage(image.getWidth(null),image.getHeight(null),BufferedImage.TYPE_INT_BGR);
Graphics2D g2d=bufImage.createGraphics();
g2d.drawImage(image,0,0,null);
return bufImage;
}
}
localJBarcode.setPainter(WideRatioCodedPainter.getInstance()); 输出条码
localJBarcode.setTextPainter(BaseLineTextPainter.getInstance()); 输出文本
public class Ean13Barcode {
private String code;
public Ean13Barcode(String code) {
super();
this.code = code;
}
public String encode() {
if (null == code) {
return "";
}
char[] codes = code.toCharArray();
int sum = 0;
for (int i = 0; i codes.length; i++) {
int num = codes[i] - '0';
if (isEven(num)) {
sum += num;
} else {
sum += num * 3;
}
}
int x = sum % 10;
return code + (x == 0 ? 0 : 10 - x);
}
private boolean isEven(int x) {
return x % 2 == 0;
}
public static void main(String[] args) {
System.out.println(new Ean13Barcode("692223361219").encode());
}
}