【发布时间】:2017-03-23 01:14:06
【问题描述】:
我有 Xamarin Android 项目,我想从相机识别二维码并同时将图片保存到存储中。我使用 Android.Hardware.Camera.IPreviewCallback 从相机获取图像。保存图像按预期工作,但二维码识别失败。这是我的代码:
void Android.Hardware.Camera.IPreviewCallback.OnPreviewFrame(byte[] data, Android.Hardware.Camera camera)
{
byte[] jpegData = ConvertYuvToJpeg(data);
Bitmap bitmap = BytesToBitmap(jpegData);
SaveBitmapImage(bitmap); // This works great
var width = (int)_textureView.Width;
var height = (int)_textureView.Height;
// How to get LuminanceSource??
//LuminanceSource source = new RGBLuminanceSource(rgbValues, bm.Width, bm.Height, RGBLuminanceSource.BitmapFormat.ARGB32);
//LuminanceSource source = new RGBLuminanceSource( jpegData, width, height);
LuminanceSource source = new PlanarYUVLuminanceSource(data, width, height,
0, 0, width, height, false);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
var result = reader.decode(binaryBitmap);
}
致电
var result = reader.decode(binaryBitmap);
总是返回 null。
编辑:
看来问题出在相机上。它不专注于二维码,图像模糊,ZXing 库无法解码。如何让相机对焦?
【问题讨论】:
标签: xamarin xamarin.android qr-code zxing