我无法使用ZXing.NET.Mobile在Xamarin中看到生成的二维码图像
本文关键字:图像 二维 ZXing NET Xamarin Mobile | 更新日期: 2023-09-27 18:24:03
请帮帮我,
我无法看到生成的二维码图像。我做错了什么!
我用过Xamarin表格。我只是简单地在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
现在将从开始读取流,而不是从结束读取流。