[英]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. 我看不到生成的QR码图像。 What am I doing wrong ! 我究竟做错了什么 !
I have used Xamarin Forms . 我用过Xamarin Forms。 I have Simply used a Image to be populated in StackLayout 我只是简单地使用了要在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. 当您使用Compress()
方法将位图数据写入MemoryStream
时,流的位置将在返回时位于结尾。
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. 现在, Image
将从头开始而不是从末尾读取流。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.