更新时间:2022-10-19 12:55:08
你应该使用 ZXingBarcodeImageView
使用系统;使用 Xamarin.Forms;使用 System.Threading.Tasks;使用 ZXing.Net.Mobile.Forms;公共类 BarcodePage : ContentPage{ZXingBarcodeImageView条码;公共条码页(){条形码 = 新 ZXingBarcodeImageView {HorizontalOptions = LayoutOptions.FillAndExpand,VerticalOptions = LayoutOptions.FillAndExpand,AutomationId = "zxingBarcodeImageView",};条形码.BarcodeFormat = ZXing.BarcodeFormat.QR_CODE;条形码.BarcodeOptions.Width = 300;条形码.BarcodeOptions.Height = 300;条形码.BarcodeOptions.Margin = 10;条形码.BarcodeValue = "Hello Stack Overflow";内容 = 条形码;}}
您可以在 Github 中查看完整示例 https://github.com/Redth/ZXing.Net.Mobile/blob/master/Samples/Forms/Core/BarcodePage.cs
I am writing an application in Xamarin to create a QR code for a given input.
using ZXing.Net.Mobile.Forms;
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new EncodingOptions
{
Height = 200,
Width = 600
}
};
var bitmap = writer.Write("Hello Stack Overflow");
How do I now display this barcode on my form?
You should use a ZXingBarcodeImageView
using System;
using Xamarin.Forms;
using System.Threading.Tasks;
using ZXing.Net.Mobile.Forms;
public class BarcodePage : ContentPage
{
ZXingBarcodeImageView barcode;
public BarcodePage ()
{
barcode = new ZXingBarcodeImageView {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
AutomationId = "zxingBarcodeImageView",
};
barcode.BarcodeFormat = ZXing.BarcodeFormat.QR_CODE;
barcode.BarcodeOptions.Width = 300;
barcode.BarcodeOptions.Height = 300;
barcode.BarcodeOptions.Margin = 10;
barcode.BarcodeValue = "Hello Stack Overflow";
Content = barcode;
}
}
You can check the full sample in Github https://github.com/Redth/ZXing.Net.Mobile/blob/master/Samples/Forms/Core/BarcodePage.cs