簡體   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