Nuget引两个包
<Image Name="image"/>
Avalonia.Media.Imaging.Bitmap bitmap = null;
if (item.Barcode == BarcodeType.QR_Code)
{var stream = CreateQRCode(item.Text, (int)width, (int)height);bitmap = new Avalonia.Media.Imaging.Bitmap(stream);image.Source = bitmap;
}
public static Stream CreateQRCode(string sContent, int width, int height,string encoding = "UTF-8"){var renderer = new SKBitmapRenderer();renderer.Background = SKColors.Transparent;renderer.Foreground = SKColors.Black;BarcodeWriter<SKBitmap> writer = new BarcodeWriter<SKBitmap>{ Renderer = renderer,Format = BarcodeFormat.QR_CODE,Options = new QrCodeEncodingOptions{CharacterSet = encoding,Margin = 1,DisableECI = true,Height = height,Width = width,ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.L,}};var skBitmap = writer.Write(sContent);Stream stream = SKImage.FromBitmap(skBitmap).Encode(SKEncodedImageFormat.Png, 100).AsStream();return stream;}