Search code examples
xamarin.ioszxing

QR code Reader Exception for Zxing


I am using the following code after taking a picture using the camera.


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

I am getting an exception from the Zxing library. Have anyone faced such an issue ? If so please do help.

I took the Zxing library from https://github.com/JohnACarruthers/zxing.MonoTouch


Solution

  • I got this working :)

    It was happening because of the large image size. I reduced the image size as follows

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

    And it worked :)