Zxing.net.mobile: ZXing Scanner Camera is not activating in UWP and WP 8.1

Created on 4 Sep 2016  路  15Comments  路  Source: Redth/ZXing.Net.Mobile

I am using the example code from the ZXing page .
Details are :
Operating System : Windows 10 Pro N
Visual Studio Enterprise 2015
Xamarin.Forms 2.3.1..114
ZXing.Net.Mobile 2.1.47
ZXing.Net.Mobile.Forms 2.1.4.7

I am using below code

btnScan.Clicked+=async(sender,e)=>{
var scanPage = new ZXingScannerPage ();
await Navigation.PushModalAsync (scanPage);
scanPage.OnScanResult += (result) => 
{
    scanPage.IsScanning = false; 
    Device.BeginInvokeOnMainThread (async () => 
    {
        await Navigation.PopModalAsync ();        
        await DisplayAlert("Scanned Barcode", result.Text, "OK");
    });
};

}

Also I have added the below line in the MainPage.xml file of the UWP project just before LoadApplication method call
ZXing.Net.Mobile.Forms.WindowsUniversal.ZXingBarcodeImageViewRenderer.Init();

Also I have provided access to the WebCam from the application manifest.

When I run the application in Debug or Release mode in the emulator then it opens the scanner but small black/white /red /green square comes and computer webcam is not accessed.
When I run it as windows 10 app then nothing comes, only blank screen comes.
When I run it in the real windows 10 mobile, then scanner opens but camera doesn't opens, the white screen with red line opens and camera doesn't activates.
The same thing happens with WIndows 8.1 also.

Any help would be deeply appreciated. I have wasted lot of time to explore the internet used almost every combination. If anyone have the solution please please provide me.

Note:
The above code works fine for Android and I am able to scan the bar code and QR code.

Most helpful comment

@F1nZeR yes!
immagine 2

All 15 comments

I'm not able to add force render er in WP8.1 how did you do that??

Have a look at the main page examples:

https://github.com/Redth/ZXing.Net.Mobile (scroll down to see the samples).

You have to call different Init() functions on different platforms.

You have to call different Init() functions on different platforms.

But the 2.1.47 NuGet packages don't install the Winphone library to the win phone project. So no init is available.

We're facing the same issue. Blank screen on UWP (both emulator and physical device Lumia 535). ZXing 2.1.47 working in Android only.

Any hint on how to solve this?

immagine 12

immagine 13

@nicolabeghin Did you include Assemblies? This may or may not be the issue.

https://github.com/Redth/ZXing.Net.Mobile/issues/409

Thanks for your kind reply. I took a look at the referenced issue, I had to use such workarounds in the past for another library and I'll surely try that ASAP. Strange thing is that I don't have any compilation or console warnings, the scanner page just stays there like that, which make the whole issue cumbersome. Both on device and emulator.

@nicolabeghin have you added "webcam" permission?

@F1nZeR yes!
immagine 2

@faceoffers28 , that did the trick!
for anyone interested: just add these lines in your App.xaml.cs

// bugfix ZXing ref. https://github.com/Redth/ZXing.Net.Mobile/issues/409
List<Assembly> assembliesToInclude = new List<Assembly>();
assembliesToInclude.Add(typeof(ZXing.BarcodeReader).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Reader).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.BaseLuminanceSource).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Binarizer).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.BinaryBitmap).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Dimension).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.LuminanceSource).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.MultiFormatReader).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.PlanarYUVLuminanceSource).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Result).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.ResultPoint).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.RGBLuminanceSource).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.SupportClass).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Net.Mobile.Forms.ZXingBarcodeImageView).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Net.Mobile.Forms.ZXingScannerPage).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Net.Mobile.Forms.ZXingScannerView).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Net.Mobile.Forms.ZXingDefaultOverlay).GetTypeInfo().Assembly);    
assembliesToInclude.Add(typeof(ZXing.Mobile.MobileBarcodeScanner).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Mobile.MobileBarcodeScannerBase).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Mobile.MobileBarcodeScanningOptions).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Mobile.ScanPage).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Mobile.MobileBarcodeScannerBase).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Mobile.SoftwareBitmapLuminanceSource).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Mobile.ZXingScannerControl).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(ZXing.Net.Mobile.Forms.WindowsUniversal.ZXingScannerViewRenderer).GetTypeInfo().Assembly);

Xamarin.Forms.Forms.Init(e, assembliesToInclude);

The only lines you actually need are:
assembliesToInclude.Add(typeof(ZXing.Net.Mobile.Forms.WindowsUniversal.ZXingScannerViewRenderer).GetTypeInfo().Assembly);
and
assembliesToInclude.Add(typeof(ZXing.Net.Mobile.Forms.ZXingScannerPage).GetTypeInfo().Assembly);

However, if no camera is available, the screen just displays a white background, which causes the app to get rejected from the windows store.

simply adding webcam permission fixed this for me!

@nicolabeghin @jasoncouture Guys, I'm going to bring you two to Las Vegas for a weekend! :卢D
Seriously now, you might have saved me many, many hours of intense frustration.
Thank you very much for sharing this!!

Can confirm, the "assembliesToInclude" method fixed this issue for me.

In App.xaml.cs, procedure "OnLaunched", replace
Xamarin.Forms.Forms.Init(e);
with

    // ZXing UWP fix for bug #409
    List<Assembly> assembliesToInclude = new List<Assembly>();



 assembliesToInclude.Add(typeof(ZXing.Net.Mobile.Forms.WindowsUniversal.ZXingScannerViewRenderer).GetTypeInfo().Assembly);
    assembliesToInclude.Add(typeof(ZXing.Net.Mobile.Forms.ZXingScannerPage).GetTypeInfo().Assembly);

    Xamarin.Forms.Forms.Init(e, assembliesToInclude);

How to add webcam rights like that

Thanks for reporting this issue! Unforunately it took me way too long to respond 馃槶. Sorry, I apologize! Recently the source code for this project was completely refactored to modernize it. Many PR's were included in this effort, and many bugs were hopefully fixed. Please try out the latest 3.x series of NuGet packages (currently in prerelease). To try and make the project more maintainable in my spare time going forward, I've decided to close all existing issues to start with a clean slate. If you're still experiencing this issue on the newest version, please open a new issue with as much detail as possible. Thank you for your patience and understanding! Happy scanning!

Was this page helpful?
0 / 5 - 0 ratings