Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Barcode rendering with ZXing.net in my Xamarin.Forms app

$
0
0

Heyo,

So I've seen a lot of posts where people need help scanning barcodes, but so far I've not seen any posts where people were having trouble rendering a barcode from a piece of data.

Our app needs to be able to display a barcode on-screen from a string. I'm using ZXing.net to render the barcode, but it's NOT able to successfully store the output in an Image. I just get this message:
[skia] --- SkImageDecoder::Factory returned null

I was able to get this to work using the ZXing Xamarin Component (before porting the app to Xamarin.Forms), I could convert the byte[] returned from ZXing to a Bitmap on Android and a UIImageView on iOS. But I can't figure out how to convert the byte[] to an ImageSource in Xamarin.Forms...

Here's my code (App.UserProfile.BarCode is a string that needs to be rendered as a barcode. _barcodeImg is an Image on the page and _label is a Label that shows the value of the barcode below the image):

public void RenderBarcode()
{
    if (App.UserProfile.BarCode != null) {
        // Create a barcode image from the user's Barcode data
        BarcodeWriter writer = new BarcodeWriter {
            Format = BarcodeFormat.CODE_39
        };

        var imageAsBytes = writer.Write(App.UserProfile.BarCode);

        // Render the image
        _barcodeImg.Source = ImageSource.FromStream (() => new MemoryStream (imageAsBytes));
        _label.Text = App.UserProfile.UserId.ToString();
    }
}

Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>