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

このデータを QR コード リーダーに送信して、QR コードをスキャンすることができます。これが役立つかどうか教えてください!

- - - アップデート - -

このような関数を使用して、ビットマップを 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 に答える