我正在尝试使用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);
}
}
答案 0 :(得分:0)
问题似乎是您将data1作为参数传递给barcode.setData方法。
您应该传递位图:barcode.setData(bitmap)
此问题与您正在使用的QR码扫描库有关。还请使用该库的相关标签对其进行标记。所以你可以得到关于该库的支持。另请检查QR码扫描库的API参考中setData方法中所需参数的要求是什么。