0

我正在尝试使用 Zbar 库为 SmartEyeGlass 开发一个扫描 QR 码的应用程序。基于示例相机扩展的应用程序。但它不起作用,我看不出问题出在哪里。这是我的代码;

private void cameraEventOperation(CameraEvent event) {
    if (event.getErrorStatus() != 0) {
        Log.d(Constants.LOG_TAG, "error code = " + event.getErrorStatus());
        return;
    }

    if(event.getIndex() != 0){
        Log.d(Constants.LOG_TAG, "not oparate this event");
        return;
    }

    Bitmap bitmap = null;
    byte[] data = null;


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



        data1= data;
         /* Instance barcode scanner */
        scanner = new ImageScanner();
        scanner.setConfig(Symbol.QRCODE, Config.X_DENSITY, 2);
        scanner.setConfig(Symbol.QRCODE, Config.Y_DENSITY, 2);
        Image barcode = new Image(width, height, "Y800");
        barcode.setData(data1);
        QRCodeStatus= scanner.scanImage(barcode);


        if (QRCodeStatus != 0) { 
        SymbolSet syms = scanner.getResults();

           for (Symbol kasa : syms) {
                  strValueOfScannedQR = String.valueOf(kasa.getData());
                 intValueOfScannedQR = Integer.valueOf(kasa.getData());
            }

       }
    }

    if (bitmap == null) {
        Log.d(Constants.LOG_TAG, "bitmap == null");
        return;
    }

    if (saveToSdcard == true) {
        String fileName = saveFilePrefix + String.format("%04d", saveFileIndex) + ".jpg";
        new SavePhotoTask(saveFolder,fileName).execute(data);
        saveFileIndex++;
    }

    if (recordingMode == SmartEyeglassControl.Intents.CAMERA_MODE_STILL) {
        Bitmap basebitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        basebitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT);
        Canvas canvas = new Canvas(basebitmap);
        Rect rect = new Rect(0, 0, width, height);
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        canvas.drawBitmap(bitmap, rect, rect, paint);

        utils.showBitmap(basebitmap);
        return;
    }

    Log.d(Constants.LOG_TAG, "Camera frame was received : #" + saveFileIndex);
    updateDisplay();
}

private void updateDisplay()
{
    Bitmap displayBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    displayBitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT);
    Canvas canvas = new Canvas(displayBitmap);
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setTextSize(16);
    paint.setColor(Color.WHITE);
    // Update layout according to the camera mode
    switch (recordingMode) {
        case SmartEyeglassControl.Intents.CAMERA_MODE_STILL:
            canvas.drawText("Tap to capture : STILL", pointX, pointY, paint);
            break;
        case SmartEyeglassControl.Intents.CAMERA_MODE_STILL_TO_FILE:
            canvas.drawText("Tap to capture : STILL TO FILE", pointX, pointY, paint);
            break;



        case SmartEyeglassControl.Intents.CAMERA_MODE_JPG_STREAM_HIGH_RATE:
            if (cameraStarted) {
                canvas.drawText("Frame Number: " + Integer.toString(saveFileIndex), pointBaseX, (pointY * 1), paint);
                canvas.drawText("Value of QR:  " + strValueOfScannedQR, pointBaseX, (pointY * 2), paint);
                canvas.drawText("Data1=" + data1, pointBaseX, (pointY * 3), paint);
                canvas.drawText("QR status  " + QRCodeStatus, pointBaseX, (pointY * 4), paint);


            }
            else {
                canvas.drawText("Tap to start JPEG Stream.", pointBaseX, pointY, paint);
            }
            break;



        case SmartEyeglassControl.Intents.CAMERA_MODE_JPG_STREAM_LOW_RATE:
            if (cameraStarted) {
                canvas.drawText("JPEG Streaming...", pointBaseX, pointY, paint);
                canvas.drawText("Tap to stop.", pointBaseX, (pointY * 2), paint);
                canvas.drawText("Frame Number: " + Integer.toString(saveFileIndex), pointBaseX, (pointY * 3), paint);
            } else {
                canvas.drawText("Tap to start JPEG Stream.", pointBaseX, pointY, paint);
            }
            break;
        default:
            canvas.drawText("wrong recording type.", pointBaseX, pointY, paint);
    }

    utils.showBitmap(displayBitmap);
}

}

4

1 回答 1

0

问题似乎是您将 data1 作为参数传递给barcode.setData 方法。

您可能应该通过位图:barcode.setData(bitmap)

这个问题与您正在使用的二维码扫描库有关。还请使用该库的相关标签对其进行标记。因此,您可以获得有关该库的支持。另请查看您的二维码扫描库 API 参考中的 setData 方法中预期参数的要求是什么。

于 2016-06-07T09:46:47.940 回答