69 ratings
  • 1
  • 2
  • 3
  • 4
  • 5
5 star 23
4 star 23
3 star 10
2 star 6
1 star 7
Compatible with
  • Windows
  • iOS
  • Android

ZXing.Net.Mobile 1.4.6

Redth

ZXing.Net.Mobile is a C#/.NET Barcode Scanning Library

ZXing.Net.Mobile is a C#/.NET library based on the open source Barcode Library: ZXing (Zebra Crossing), using the ZXing.Net Port. It works with Xamarin.iOS, Xamarin.Android, and Windows Phone. The goal of ZXing.Net.Mobile is to make scanning barcodes as effortless and painless as possible in your own applications!

GitHub Project: https://github.com/Redth/ZXing.Net.Mobile

Usage

buttonScan.Click += (sender, e) => {

  //NOTE: On Android, you MUST pass a Context into the Constructor!
    var scanner = new ZXing.Mobile.MobileBarcodeScanner();
    var result = await scanner.Scan();

  if (result != null)
    Console.WriteLine("Scanned Barcode: " + result.Text);
};

Features

  • Xamarin.iOS
  • Xamarin.Android
  • Windows Phone
  • Simple API - Scan in as little as 2 lines of code!
  • Scanner as a View - UIView (iOS) / Fragment (Android) / Control (WP)

Custom Overlays

By default, ZXing.Net.Mobile provides a very simple overlay for your barcode scanning interface. This overlay consists of a horizontal red line centered in the scanning 'window' and semi-transparent borders on the top and bottom of the non-scanning area. You also have the opportunity to customize the top and bottom text that appears in this overlay.

If you want to customize the overlay, you must create your own View for each platform. You can customize your overlay like this:

var scanner = new ZXing.Mobile.MobileBarcodeScanner();
scanner.UseCustomOverlay = true;
scanner.CustomOverlay = myCustomOverlayInstance;
var result = await scanner.Scan();
//Handle result

Keep in mind that when using a Custom Overlay, you are responsible for the entire overlay (you cannot mix and match custom elements with the default overlay). The ZxingScanner instance has a CustomOverlay property, however on each platform this property is of a different type:

  • Xamarin.iOS => UIView
  • Xamarin.Android => View
  • Windows Phone => UIElement

All of the platform samples have examples of custom overlays.

Barcode Formats

By default, all barcode formats are monitored while scanning. You can change which formats to check for by passing a ZxingScanningOptions instance into the StartScanning method:

var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
options.PossibleFormats = new List<ZXing.BarcodeFormat>() { 
  ZXing.BarcodeFormat.Ean8, ZXing.BarcodeFormat.Ean13 
};

var scanner = new ZXing.Mobile.MobileBarcodeScanner();
var result = await scanner.Scan(options);
//Handle result

Using the ZXingScanner View / Fragment / Control

On each platform, the ZXing scanner has been implemented as a reusable component (view, fragment, or control), and it is possible to use the reusable component directly without using the MobileBarcodeScanner class at all. On each platform, the instance of the view/fragment/control contains the necessary properties and methods required to control your scanner. By default, the default overlay is automatically used, unless you set the CustomOverlay property as well as the UseCustomOverlay property on the instance of the view/fragment/control. You can use methods such as ToggleTorch() or StopScanning() on the view/fragment/control, however you are responsible for calling StartScanning(...) with a callback and an instance of MobileBarcodeScanningOptions when you are ready for the view's scanning to begin. You are also responsible for stopping scanning if you want to cancel at any point.

The view/fragment/control classes for each platform are:

  • iOS: ZXingScannerView (UIView) - See ZXingScannerViewController.cs View Controller for an example of how to use this view
  • Android: ZXingScannerFragment (Fragment) - See ZXingActivity.cs Activity for an example of how to use this fragment
  • Windows Phone: ZXingScannerControl (UserControl) - See ScanPage.xaml Page for an example of how to use this Control

Using Apple's AVCaptureSession (iOS7 Built in) Barcode Scanning

In iOS7, Apple added some API's to allow for scanning of barcodes in an AVCaptureSession. The latest version of ZXing.Net.Mobile gives you the option of using this instead of the ZXing scanning engine. You can use the AVCaptureScannerView or the AVCaptureScannerViewController classes directly just the same as you would use their ZXing* equivalents. Or, in your MobileBarcodeScanner, there is now an overload to use the AV Capture Engine:

//Scan(MobileBarcodeScanningOptions options, bool useAVCaptureEngine)
scanner.Scan(options, true);

In the MobileBarcodeScanner, even if you specify to use the AVCaptureSession scanning, it will gracefully degrade to using ZXing if the device doesn't support this (eg: if it's not iOS7 or newer), or if you specify a barcode format in your scanning options which the AVCaptureSession does not support for detection. The AVCaptureSession can only decode the following barcodes:

  • Aztec
  • Code 128
  • Code 39
  • Code 93
  • EAN13
  • EAN8
  • PDF417
  • QR
  • UPC-E

Release Notes

1.4.6

  • Android: Resolution Selector Delegate now in MobileBarcodeScanningOptions
  • iOS: Resolution Selector Delegate now in MobileBarcodeScanningOptions
  • Updated Android Support v4 library to rev 20.0.0.3
  • Bugfixes

1.4.5

  • Updated Android Support v4 library to rev 20
  • Updated ZXing.Net reference (several improvements)
  • Bugfixes

1.4.4

  • Android: Fixed bug causing scanning not to occur in some timezones
  • iOS: Fixed cosmetic issue where loading black screen would be raised in portrait
  • All: Updated ZXing.Net - Better Code39 scanning and memory/performance improvements

1.4.3

  • Android: Major performance improvements
  • Android: Fixed fragment resume
  • iOS: Bug fix - Scanner wasn't entering stopped state always
  • Windows Phone: Fixed preview not starting in some cases
  • All: Updated to newer ZXing.Net with performance improvements and bugfixes
Write a Review

24 reviews

shanminxu rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

on simulator compiles ok, when deploy to iOS devices, debug or release, got this error:

error MT2002: Failed to resolve "MonoTouch.Foundation.NSString MonoTouch.AVFoundation.AVCaptureSession::get_Preset1920x1080()" reference from "monotouch, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065”

I checked the mono reference, it does not have preset 1920x1080, don't know why.

Any help is really appreciated, Thanks!

Posted on: August 11 / Version: 1.4.6
Zhu David

Hi, is there anyone could provide the complete sample code to generate QR code and display in content page, thx!

Posted on: July 29 / Version: 1.4.5
Mathew Twardowski rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Works okay. Would be nice if the heuristics on the QR code accounted for some damage on the 3 corner marks on the QR tags, but repairing these marks with a pen works okay. If we needed more data protection we'd have used RFID tags.

Also, don't know if it's how I implemented it, but I did see it on the iOS sample, but when launching the scanner on an iPad in landscape orientation, the loading overlay doesn't resize to the screen in that orientation. I used a pure black view to mask the screen so it doesn't look as bad, and hide it when scanning complete.

Posted on: May 16 / Version: 1.4.4
John Rowse rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

I am trying the sample app on android 4.0.1 (samasung galaxy tab 2), and the only barcodes I can scan are ones I have brought up on google image, blown up in high resolution. Standard barcodes you get on the back of a book or tin of beans, do not work. Any reason why I could be having issue? Before you ask, I have tried in good light, and slowly adjusted the distance to get the optimal focus and range. A supermarket app I have installed, that uses the same sort of process, scans without issue.

Posted on: April 10 / Version: 1.4.4
Paul Auman rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Great Job! Here is an example of generating QR code(s) with ZXing and MT

[code]

using ZXing; using ZXing.Mobile; using ZXing.QrCode; using ZXing.Common;

….

QRCodeWriter writer = new QRCodeWriter(); ZXing.Common.BitMatrix matrix;

int size = 120; matrix = writer.encode("http://aumansoftware.com;", BarcodeFormat.QR_CODE, size, size, null);

SizeF qrcCodeSize = new SizeF(size,size);

UIGraphics.BeginImageContext(qrcCodeSize);

using (CGContext cont = UIGraphics.GetCurrentContext()) { cont.SetLineWidth(1); cont.SetFillColor(UIColor.White.CGColor); cont.AddRect(new RectangleF(0,0,qrcCodeSize.Width,qrcCodeSize.Height)); cont.DrawPath(CGPathDrawingMode.Fill);

                    cont.SetFillColor(UIColor.Black.CGColor);


                    for (int y = 0; y < matrix.Height; y++)
                    {
                        for (int x = 0; x < matrix.Width; x++)
                        {

                            if(matrix[x,y]) cont.AddRect(new RectangleF(x,y,1,1));


                        }

                    }


                    cont.DrawPath(CGPathDrawingMode.Fill);

                    UIImage qrcImage = UIGraphics.GetImageFromCurrentImageContext();

// show image in imageview UIImageView qrcImageView defined earlier... qrcImageView.Image = qrcImage; qrcImageView.SetNeedsDisplay();

}//end using cont

UIGraphics.EndImageContext();

[/code]

Cheers,

Paul Auman Auman Software, LLC

Posted on: April 8 / Version: 1.3.5
George Polites rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

I have been trying for over two days to make it recognize EAN 13 barcodes with different devices. I started with an iPod touch (4th Gen) and when I saw that it does not recognize I tried with iPad 3 and then iPhone 4s under different light conditions (flash no flash etc.) I have a similar project with Objective-C and ZBar and I had no problem even with the terrible camera of the iPod touch. In my trials I got some scans but I had to move the device trying for the best shot for several minutes each time. Tried different options but no luck.

Posted on: April 8 / Version: 1.3.5
Rogier Rietdijk rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

The scanner became slow after 4/5 times use.

Posted on: April 8 / Version: 1.3.7
Joshua Krebs rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

I, much like Rogier Rietdijk am experiencing the same issue with the scanner becoming slow after 4/5 times use. It would be great if we could figure out what is causing this... it seems to only affect iOS. The Android version works GREAT!

Posted on: April 8 / Version: 1.3.7
Matt Cuda rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

This is a good component for everyday scanning where scan time is not that crucial, but it does not compare to products such as RedLaser and Scandit. My big request right now is that the author spend some time optimizing this product to take it from good to great!

Update: I am infrequently running into an issue where the camera does not close propertly or does not open properly, but the end result is that the aperature image on the camera stays shut and will not open up so the user can scan.

Posted on: April 8 / Version: 1.3.3
Rupesh Bhavsar

I have integrated above barcode scanner to my solution in Xamarin. There are no exceptions,but when iam going to scan any code using the solution,iam not getting any result,it keeps on scanning all the time,until i stops. What could be the problem? Can any one help.

Posted on: April 8 / Version: 1.4.3
Pavel Szypka

Same problem for me as Rupesh Bhavsar. I am just stuck at scanning but with no result. (tested on Huawei G510, G300 and Sony Xperia Pro mini)

Posted on: April 8 / Version: 1.4.3
shaghayegh hadadi

this android sample can't build .it makes error !

error is: cannot find all required by the 'async' modifier.

Posted on: April 8 / Version: 1.4.3
Magdy Sharkawy rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Just compiled the sample application in V 1.4.0, unfortunately the camera starts with 90 degree rotation. Please solve this issue or advice how to solve it.

Posted on: April 8 / Version: 1.4.0
ding ling rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Just return one result that many barcode in the scan screen. Cloud it return more result?and the read speed is slower.

Posted on: April 8 / Version: 1.4.0
Robert rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Wow! I must say, I am very impressed with how simple this is. This doesn't have a bunch of .dll references or 1300+ lines of code.

Posted on: April 8 / Version: 1.4.0
Craig Schulte rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Ok, it took me awhile to get this working on Android, but once I did it was great. Documentation and examples could be improved slightly to make 1st time implementation easier, otherwise lazy developers like myself will just assume it's broken and move on. 2 things to note: Android requires you to provide a Context in the constructor, and you also must include the camera permission (duh). Once I found the demo project it helped a lot, but I didn't notice it at first.

Haven't tested it on many devices yet - so far just the Galaxy S3.

Overall, big time saver, thanks.

Posted on: April 8 / Version: 1.3.3
Vitor Barbosa rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Good component, but as Craig said in his review, on Android you must provide a context to the MobileBarcodeScanner constructor, otherwise it won't work.

Another gripe of mine is that the whole project is downloaded when you add this component to a project, which leaves you with around 8MB of source code. I added that folder to my svn ignore list, but other components don't seem to require this.

Posted on: April 8 / Version: 1.3.3
Alexey Bogdanov rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Gives a "Error MT2002: Failed to resolve "System.Boolean System.Type::op_Equality(System.Type,System.Type)" reference from "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" (MT2002)" error.

Posted on: April 8 / Version: 1.3.3
Le-roy Staines

I also get the 'System.boolean' error! Help!

EDIT: Downloaded the source from https://github.com/Redth/ZXing.Net.Mobile and recompiled the DLL's and it worked :)

Posted on: April 8 / Version: 1.3.3
Michael Rutherford rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Very nice component - but it's still a beta product.

I was able to swap out the RedLaser component with a couple of hours work (total) - I added the component, changed a few references, tweaked some code, dropped the Redlaser files and modified TFS appropriately. I set it to scan only UPC and EAN codes and it performed very well. My project is an iOS presales app for beer, wine and soda distributors.

I bumped into an issue that caused me to remove the component (temporarily). When I called up the scan overlay, and was put into background mode, I called the Cancel() method on the scanner. But, when my app re-entered the foreground, the camera wouldn't re-open (probably a straightforward fix).

Also, the documentation could do with a refresh - although the sample project for iOS was very useful.

I'm really looking forward to the next update :)

Posted on: April 8 / Version: 1.3.3
Justin Moses rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

I'm a big fan of this component. I love the customization options now, my only concern at this point (in IOS), is that I have no way to open a new window immediately upon capturing a result without going into the rootviewcontroller's ViewDidAppear method.. and using some kind of internal variable. Right now there is no event exposed that tells me when the Viewcontroller that hosts the UIView for the scanner.. has been dismissed.

Posted on: July 17, 2013 / Version: 1.3.5
Benjamin Soulier rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Works great now, thanks for the update!

Posted on: June 19, 2013 / Version: 1.3.3
Justin Moses rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Just wanted to say that I use this component pretty frequently, and it works great. : )

Posted on: June 18, 2013 / Version: 1.3.2
Benjamin Soulier rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Impossible to use on Xamarin.IOS, giving a "Error MT2002: Failed to resolve "System.Boolean System.Type::op_Equality(System.Type,System.Type)" reference from "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" (MT2002)" error.

Too bad..

Posted on: June 17, 2013 / Version: 1.3.3