2013-12-13 90 views
0

我有一个代码来解码图像文件并解码它的qrcode。我正在使用zxing库。但我怎么能让这个从网络摄像头捕捉qrcode并解码它。我需要做什么改变?任何一个人都可以一步一步解释这一点。如何使用zxing通过网络摄像头解码qrcode

这里是代码:

public class QrCodeDecoder 
{ 
    public String decode(File imageFile) 
    { 
     BufferedImage image; 
     try 
     { 
      image = ImageIO.read(imageFile); 
     } 
     catch (IOException e1) 
     { 
     return "io outch"; 
     } 

     // creating luminance source 
     LuminanceSource lumSource = new BufferedImageLuminanceSource(image); 
     BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(lumSource)); 

     // barcode decoding 
     QRCodeReader reader = new QRCodeReader(); 
     Result result = null; 
     try { 
      result = reader.decode(bitmap); 
     } 
     catch (ReaderException e) 
     { 
     return "reader error"; 
     } 

     return result.getText(); 

     } 

} 

回答

0

你很远,从一个解决方案,我不认为任何人都可以解释为“分步实施”。您首先需要找到能够从网络摄像头抓取图像的库。您可以从this library开始,但我确定有其他人。

一旦你可以捕捉图像,开始找出它是否在上述代码预期的格式。如果你幸运的话,那将是,如果没有,你将不得不在两种格式之间进行转换。