如何将QR码阅读应用程序集成到Sony SmartEyeGlass?

时间:2016-05-03 10:04:17

标签: android-studio sony sony-smarteyeglass

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

1 个答案:

答案 0 :(得分: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);
    }

您可以获取此数据并将其发送到QR码阅读器以扫描QR码。如果这有帮助,请告诉我!

-----更新----

您可以使用这样的函数将位图传递给Google Zxing库。使用应该像Async任务一样:

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;
}