guangtouhaky 2015-03-19 01:29 采纳率: 0%
浏览 1849

java利用zxing包解二维码

我在网上找了一个解二维码的代码,利用的zxing包的功能解码,代码和zxing包都是现成的,编译通过然后运行是有些二维码能解析出来,有些就解析不出来。求大神
package test;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import java.net.URLDecoder;

import java.util.EnumMap;

import java.util.Map;

import javax.imageio.ImageIO;

import com.google.zxing.BinaryBitmap;

import com.google.zxing.BufferedImageLuminanceSource;

import com.google.zxing.DecodeHintType;

import com.google.zxing.LuminanceSource;

import com.google.zxing.MultiFormatReader;

import com.google.zxing.Reader;

import com.google.zxing.ReaderException;

import com.google.zxing.Result;

import com.google.zxing.common.HybridBinarizer;

public class ZxingPdfRead {

private static Reader barcodeReader = new MultiFormatReader();

/** 
 * @param args 
 * @throws IOException 
 */  
public static void main(String[] args) throws Exception {  
    File testImage = new File(  
            "E:\\work\\all_workspace\\wp_zxing\\barcode4jTest\\src\\test\\helloworld.png");  

    BufferedImage image = ImageIO.read(testImage);  

    LuminanceSource source = new BufferedImageLuminanceSource(image);  

    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));  

    try {  
        Map<DecodeHintType, Object> hints = new EnumMap<DecodeHintType, Object>(  
                DecodeHintType.class);  

        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);  

        Result result = barcodeReader.decode(bitmap, hints);  

        String resultText = result.getText();  

        System.out.println("resultText:" + URLDecoder.decode(resultText, "UTF-8"));  
    } catch (ReaderException ignored) {  
        ignored.printStackTrace();  
    }  
}  

}

  • 写回答

2条回答 默认 最新

  • threenewbee 2015-03-19 06:55
    关注

    解析不出来很正常,图片解析度太低,编码不标准,拍照没有对焦,过于偏斜等等都会识别不出来。

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序