我在网上看到了很多相关内容(旧帖子),但似乎没有什么能解决我的问题。我正在尝试将一个字符串生成二维码并在应用程序中显示。
以下是我最初的代码:
qrCode = new ZXingBarcodeImageView
{
BarcodeFormat = BarcodeFormat.QR_CODE,
BarcodeOptions = new QrCodeEncodingOptions
{
Height = 50,
Width = 50
},
BarcodeValue = codeValue,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand
};
这对于Android设备没问题,但在IOS设备上根本没有渲染。因此,在进行研究后,我尝试像这样做:
Image qrCode;
if (Device.OS == TargetPlatform.iOS)
{
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new ZXing.Common.EncodingOptions
{
Width = 50,
Height = 50
}
};
var b = writer.Write(codeValue);
qrCode = new Image
{
Aspect = Aspect.AspectFill,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
Source = ImageSource.FromStream(() =>
{
MemoryStream ms = new MemoryStream(b);
ms.Position = 0;
return ms;
})
};
}else{
qrCode = new ZXingBarcodeImageView
{
BarcodeFormat = BarcodeFormat.QR_CODE,
BarcodeOptions = new QrCodeEncodingOptions
{
Height = 50,
Width = 50
},
BarcodeValue = codeValue,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand
};
}
Content = new StackLayout
{
Children = {
header, lblExplenationText, qrCode
},
BackgroundColor = Color.White
};
但是仍然没有任何渲染出来。
ZXing.Mobile.Forms NuGet包版本:2.1.47(最新版)