简体   繁体   中英

I am not able see generated QR Code Image in Xamarin using ZXing.NET.Mobile

Please help me ,

I am not able see generated QR Code Image. What am I doing wrong !

I have used Xamarin Forms . I have Simply used a Image to be populated in StackLayout

public class BarcodePage : ContentPage
{
    public BarcodePage ()
    {
        Image img = new Image {
            Aspect = Xamarin.Forms.Aspect.AspectFit
        };


        img.Source = ImageSource.FromStream (() => {
            var writer = new BarcodeWriter {
                Format = BarcodeFormat.QR_CODE,

                Options = new EncodingOptions {
                    Height = 200,
                    Width = 600
                }
            };
            var bitmap = writer.Write ("My Content");

            MemoryStream ms = new MemoryStream ();
            bitmap.Compress (Bitmap.CompressFormat.Jpeg, 100, ms);
            return ms;
        });

        var Layout = new StackLayout {
            Children = 
            { img}
        };

        Content = Layout;

}

As you are writing the Bitmap data to the MemoryStream using the Compress() method the position of the stream will be at the end when you return it.

Make sure to reset the stream's position before returning it by adding this line.

ms.Position = 0;

The Image will now read the stream from the beginning, rather than from the end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM