【问题标题】:QR code Reader Exception for ZxingZxing 的二维码阅读器异常
【发布时间】:2023-03-13 14:43:01
【问题描述】:

我在使用相机拍照后使用以下代码。


UIimage img = e.Info[UIImagePickerController.OriginalImage] as UIImage;
imagePicker.DismissModalViewControllerAnimated(true);
try
{

    var srcbitmap = new System.Drawing.Bitmap(img);

     Reader barcodeReader = new MultiFormatReader();
     LuminanceSource source = new RGBLuminanceSource(srcbitmap,(int)image.Size.Width, (int)image.Size.Height);
  BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
  var result = barcodeReader.decode(bitmap);

我从 Zxing 库中得到一个异常。有没有人遇到过这样的问题? 如果是这样,请帮忙。

我从https://github.com/JohnACarruthers/zxing.MonoTouch拿了Zxing库

【问题讨论】:

  • ...什么例外? NotFoundException 是正常的,只是没有检测到。
  • 异常来自 LuminsSource 构造函数和 bitmap.cs(getPixel) 函数。
  • ...而且,它是什么异常?你并没有真正提供太多信息。
  • 抱歉回复晚了,我收到以下异常:异常:System.IndexOutOfRangeException:数组索引超出范围。在 System.Drawing.Bitmap.GetPixel (Int32 x, Int32 y) [0x00000] 在 :0

标签: xamarin.ios zxing


【解决方案1】:

我得到了这个工作:)

发生这种情况是因为图像尺寸过大。我将图像尺寸缩小如下

            UIGraphics.BeginImageContext(new SizeF(480,320));
            image.Draw(new RectangleF(0,0,200,200));
            UIImage smallImage = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext(); 

它成功了:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    相关资源
    最近更新 更多