Forum Cross Platform with Xamarin

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

ZxingSharp.Mobile - Cross Platform Barcode Scanning

245

Posts

  • DigitalNutDigitalNut CAMember

    Hi all,

    We are also had problems with reading QR code. Looks like screen/camera coordinates setting may not be correct. I quickly compared the output of the Java version and they don’t seem to match. Did a quick hack and got QR reading, but now 1D stuff is broken…Still debugging.

  • MichaelJahnMichaelJahn DEMember

    If you use the original source of ZXing.Net.Mobile from Jonathan (https://github.com/Redth/ZXing.Net.Mobile) please update the ZXing.Net part to the latest source from https://zxingnet.svn.codeplex.com/svn/trunk.
    I made some important changes to the QR Code decoding part for mobile platforms.

    Michael

  • OldRedthOldRedth USMember, Insider ✭✭✭

    I'll update my source to match the latest source from @micjahn asap!

  • JonCoxJonCox USMember, Beta

    Hi All

    I have been trying to use the Zxing.Net.Mobile to scan a combination of 1D and Data Matrix barcodes. The sample application works well in basic test cases. However, the application that I am working on requires small Data Matrix to be scanned. I have attached a sample of a barcode that the application is required to scan, required size is 11mm * 11mm. Unfortunatly, I can not seem to get the demo to scan this barcode. Please could anyone have a look and let me know how you get on. The barcode has been tested with a scanner, and it is readable.

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @JonCox it may be worth trying to simply get ZXing.Net http://zxingnet.codeplex.com/ working without the Mobile part in the equation, to see if ZXing.Net itself is capable of scanning this barcode (which is the underlying engine ZXing.Net.Mobile uses). Unfortunately, I'm not a great help when it comes to the inner workings of ZXing, and you may have better luck asking @micjahn for this part. He's the brains behind porting all the ZXing stuff over. I've simply leveraged his work to build a MonoTouch / Mono for Android / Windows Phone component.

  • JonCoxJonCox USMember, Beta

    Thank you for your reply. I will have a go and let you know if I find anything.

  • @Redth Hi Jon - Any chance you could update your source with the QR code fix from @micjahn? Many thanks

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @RichardKershaw yep, it's on the list, sorry just been busy with other things the last little while. I'm hoping to dedicate some time to show my open source projects some love in the next few days though!

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @RichardKershaw I've updated to the latest ZXing.Net source from @micjahn

    I've also merged a nice little pull request from AMersch which includes a couple enhancements and a couple bugfixes

  • @Redth Thanks Jonathan. I downloaded the latest source and built ZXing.Net.Mobile.MonoForAndroid.sln, but QR code reading still does not work for me I'm afraid. Decoding the barcode here works fine: http://en.wikipedia.org/wiki/File:UPC_A.svg, but decoding the QRcode here doesn't: http://upload.wikimedia.org/wikipedia/commons/9/9b/Wikipedia_mobile_en.svg. Tested on both LG Optimus One (Froyo) or Google Nexus S (JellyBean).

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @RichardKershaw I'll take a look at the QR code and see if I can get it working here...

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @RichardKershaw give it one more try for me now! I changed how the camera preview data was being obtained and now am running it through a proper android YuvImage object to get the actual yuv data to feed to the luminance source.

    The end result is that I'm now able to scan QR and DataMatrix fine :)

    I am still seeing some problems with PDF417 scanning that I'll talk to @micjahn about since those formats aren't working in my unit tests either...

  • @Redth Cheers Jonathan! We're definately getting somewhere - my LG Optimus One (Froyo) can now scan QR codes now (although it does take a little time - 5 to 10 seconds), but my Google Nexus S (JellyBean) can't. Are there any settings you think I can tweak in order to get a good scan?

    Thanks again!

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @RichardKershaw I found that you had to hold the camera further back than felt natural with QR Codes... try holding it further away from the QR Code.. I got them to scan in < 1 second on my devices (Galaxy S and Nexus 4)

  • OldRedthOldRedth USMember, Insider ✭✭✭

    PDF-417 does seem to work, I was just doing something wrong...

  • @Redth Thanks Jonathan - just tried again ... looks like the Nexus S was just having issues - it's fine scanning QR codes now. Good work and thanks again!

  • tmarestmares USMember

    @Redth Great project! I do have one question though. I got the project running on my iOS app but when I run on Android my status is coming back as "faulted." Have you ever seen this? (it works fine when I run the sample project) Below is the code I am using.

    var scanner = new MobileBarcodeScanner();
    scanner.UseCustomOverlay = false;
    scanner.Scan().ContinueWith((t) => {
    if(t.Status == System.Threading.Tasks.TaskStatus.RanToCompletion){
    this.ListView.FilterText = r.Result.Text; // puts value into search bar
    }
    }

    Any suggestions you may have are greatly appreciated! Sorry if this question seems basic but I'm fairly new to mobile.

  • ShanShan CAMember

    @Redth Thanks for the excellent project. I have downloaded the sample monotouch project and tired it in my iPad. I noticed that the scanner doesn't work properly in the landscape mode. I have to place the barcode line right angle to the red line in the landscape mode, but it works perfectly in portrait mode. I tried fixing the redline to draw 100% width in landscape, but it didn't work.

  • tmarestmares USMember

    @Shan I noticed this as well. What I did was lock the orientation into Portrait. To do this I added to the ZxingCameraViewController in Zxing.Net.Mobile, code below (not sure if this helps you or anyone else):

    public override bool ShouldAutorotate ()
    {
    return false;
    }

    public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
    {
    return false;
    }

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()
    {
    return UIInterfaceOrientationMask.Portrait;
    }

  • ShanShan CAMember

    @tmares - I tried your code in ZxingCameraViewController, but no luck.

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @Shan I haven't really tested it on iPad myself... I need to get around to that. Sorry, but that's all I've got at this point....

    @RichardKershaw you may be interested in the latest source on master, @micjahn has added some very nice changes to help Android scanning :)

  • ShanShan CAMember

    Thanks @Redth, I will also try to fix the issue and keep you posted.

  • pauldpauld USMember ✭✭
    edited February 2013

    I'm able to get the scanner to work on an iOS device, but I'm struggling to find a way to update my MonoTouch.Dialog UI with the result. Sounds simple doesn't it?

    I have an EntryElement (barcodeElement) and a StringElement acting as a button to initiate the scan. I'm using an EntryElement because I'm required to allow the user to enter the value if the scan doesn't work. Tapping the StringElement starts the scanner:

    button.Tapped += delegate{
        var scanner = new ZXing.Mobile.MobileBarcodeScanner();
        scanner.Scan(scanoptions).ContinueWith(t => {   
            if (t.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
            {
                if (t.Result != null && !string.IsNullOrEmpty(t.Result.Text))
                {
                    string barcode = t.Result.Text;
                    Console.WriteLine("Scanned Barcode: " + barcode);
    
                    this.InvokeOnMainThread ( () =>
                    { 
                        // Update the UI with the scanned value
                        barcodeElement.Value = barcode;
                    });
                }
            }
        });
    };
    

    The problem is that barcodeElement.Value, which updates the UITextField in the EntryElement, doesn't visually update the code on screen. I think either UIKit or MonoTouch.Dialog's DialogViewController has already done its redraw and doesn't respond to the change. The main issue is that the Scan() method's Task doesn't return until the calling view controller - a DialogViewController - has been redisplayed. It's ViewWillAppear and ViewDidAppear have already been called by the time I try to set the code in the UI.

    What can I do to get the scanned value earlier, or to force a refresh of the EntryElement's UITextField when it's already been drawn. It seems simple but I've spent the better part of a day on this. What am I missing?

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @pauld what if you call TableView.ReloadData() after updating the element.Value ?

  • ShanShan CAMember

    @Redth - Quick update on the iPad orientation issue. This issue is happening only on iOS 5, but not on iOS 6. It looks like a bug in iOS 5.

  • OldRedthOldRedth USMember, Insider ✭✭✭
    edited March 2013

    @Shan unfortunately I don't have any iOS5 devices anymore... Are you able to determine a fix for iOS 5?

    If possible, please open an issue on the GitHub project site for this and we can continue the discussion there :)

    Thanks for looking into this!

  • pauldpauld USMember ✭✭
    edited March 2013

    @Redth, thanks, I tried that already but it still didn't update. I suspect it's more of an MT.D issue.

    I ended up trying the MT bindings of Zbar and the way that provides a ViewController that you present and dismiss fitted into my application a lot better, so at the moment I'll be using that one.

  • RichardKershawRichardKershaw GBBeta ✭✭

    @Redth - I don't suppose you know of any reason why linear barcodes might cause scanning problems, do you? QR scanning's working well now, but as for Code 39, ITF etc, no cigar.

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @RichardKershaw is this on Android? If so, there's still an issue with scanning 1D on Android in portrait (it seems to work if you rotate the device which makes no sense)

    Anyone who's having issues on Android, I'm in the process of making a test app to capture some sample YUV data that @micjahn can then analyze to see if he can identify why the scan wouldn't be working... Sorry it's taking longer than I expected due to some other commitments, but it will be soon!

  • RichardKershawRichardKershaw GBBeta ✭✭

    @Redth - it's Android, and you're spot on about the landscape scanning.

  • Hi all,

    I've added the Zinq.Net.Mobile as component from the component store in Visual Studio 2010.
    The problem is that the example is not working.

    What am I doing wrong?

    Gert-Jan

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @Gert-JanNaaktgeboren can you be more specific about what errors or problems you are having?

  • @Redth I've added the component to my visual studio project by using "Get more components" and then selecting the ZXing.Net.Mobile component.
    I'm building an android app.

    I've added a button to a layout and added the code from the example to the activity class.
    When I click the button the scanner is shown but when I try to scan a barcode (EAN13) it never return a value.
    When I do the same in the sample project it works without any problems.

  • @Redth I've attached a small sample project.

  • OldRedthOldRedth USMember, Insider ✭✭✭
    edited March 2013

    EDIT - Ignore original thought. The component is probably still at version 1.3.2 for you. This has a known issue with scanning 1D barcodes on Android. It's been fixed in 1.3.3 which should be released any minute now (it's pending approval on the component store).

    Please wait until 1.3.3 is released, or alternatively, you could build source from the GitHub project and use that.

  • @Redth The version is indeed 1.3.2.
    I will keep an eye on the component store to see if there is a new version and will let you know if it works.

  • @Redth I've looked in the component store but the version is still 1.3.2
    Do you have an update when the new version will be available?

  • OldRedthOldRedth USMember, Insider ✭✭✭

    Sorry, I'm waiting for Xamarin to approve it.... Not sure how long it will be!

  • OldRedthOldRedth USMember, Insider ✭✭✭

    @Gert-JanNaaktgeboren it's updated now on the component store :)

  • @Redth It working now.
    That's for the quick fix.

Sign In or Register to comment.