0

我们正在为 Sony SmartEyeGlass 开发应用程序。首先,我们使用 Android Studio 和 android 平板电脑创建它。现在,我们正在使用 Sample Camera Extension 示例将其集成到我们的项目中。但是有很多细节。有人可以帮助解决这个问题吗?

4

1 回答 1

0

Sample Camera 扩展是开始构建 QR 码阅读器的好地方。在 SampleCameraControl.java 中有一个名为 cameraEventOperation 的函数。在此函数中,您将看到如何将相机数据下拉到位图中的示例。这是供参考的代码:

private void cameraEventOperation(CameraEvent event) {

    if ((event.getData() != null) && ((event.getData().length) > 0)) {
        data = event.getData();
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
    }

您可以获取此数据并将其发送到您的二维码阅读器以扫描二维码。让我知道这是否有帮助!

- - - 更新 - -

您可以使用这样的函数将位图传递给 Google Zxing 库。使用应该把它放在类似异步任务的东西中:

import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException;
import com.google.zxing.DecodeHintType;
import com.google.zxing.FormatException;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.RGBLuminanceSource;
import com.google.zxing.Reader;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
//This function sends the provided bitmap to Google Zxing
public static String readBarcodeImage(Bitmap bMap) {
    String contents = null;

    int[] intArray = new int[bMap.getWidth()*bMap.getHeight()];  
    //copy pixel data from the Bitmap into the 'intArray' array  
    bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());  

    LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(), intArray);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

    Reader reader = new MultiFormatReader();// use this otherwise ChecksumException
    try {

        Hashtable<DecodeHintType,Object> hints=new Hashtable<DecodeHintType,Object>();
        hints.put(DecodeHintType.TRY_HARDER,Boolean.TRUE);

        Vector<BarcodeFormat> decodeFormats = new Vector<BarcodeFormat>();

        decodeFormats.add(BarcodeFormat.QR_CODE);

        hints.put(DecodeHintType.POSSIBLE_FORMATS,decodeFormats);

        Result result = reader.decode(bitmap, hints);
        BarcodeFormat format = result.getBarcodeFormat();
        contents = result.getText() + " : "+format.toString();

    } catch (NotFoundException e) { e.printStackTrace(); } 
    catch (ChecksumException e) { e.printStackTrace(); }
    catch (FormatException e) { e.printStackTrace(); }
    return contents;
}    
于 2016-05-03T22:26:45.553 回答