繁体   English   中英

我无法使用ZXing.NET.Mobile在Xamarin中看到生成的QR码图像

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

请帮我 ,

我看不到生成的QR码图像。 我究竟做错了什么 !

我用过Xamarin Forms。 我只是简单地使用了要在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;

}

当您使用Compress()方法将位图数据写入MemoryStream时,流的位置将在返回时位于结尾。

通过添加此行,请确保在返回流之前重置流的位置。

ms.Position = 0;

现在, Image将从头开始而不是从末尾读取流。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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