Search code examples
iosxamarinmvvmcrossqr-codezxing

Write QR-Code failed


I have a project using Xamarin with MvvmCross. In this project i want to create a QR-Code in a MvvmCross Plugin. I have it working in the Android plugint. However, the iOS plugin creates an corrupted image, which I cannot open after creation.

I use ZXing.Net PCL (Version: 0.14.0.1)

My code:

public byte[] GenerateQrImage(string content, int width, int height)
{
    if (string.IsNullOrEmpty(content) || width <= 0 || height <= 0) return null;

    var options = new QrCodeEncodingOptions
    {
        Height = height,
        Width = width,
        Margin = 0,
        PureBarcode = true
    };

    var writer = new BarcodeWriter
    {
        Format = BarcodeFormat.QR_CODE,
        Options = options
    };

    // Get bytes
    return writer.Write(content);
}

The above code returns a byte array which I can save. When I open the application folder on my Mac, I cant open the image (I think its corrupt).

Can anyone tell me, how i can solve this problem? Thanks


Solution

  • After many tests (and also many fails) i found the solution. I took the wrong nuget-package. Just reference to Zxing.Net.Mobile and the qr-image generation works.

    At the end it's the same problem described here.