如何在Winui 3应用程序中显示位图对象
我想显示QRCoder库生成的QR码()在我的Winui 3桌面应用中。
从qrcoder i获得system.bitmap
对象:
QRCodeGenerator qrCodeGenerator = new();
QRCodeData qrCodeData = qrCodeGenerator.CreateQrCode(associateSoftwareTokenResponse.SecretCode, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new(qrCodeData);
Bitmap qrCodeBitmap = qrCode.GetGraphic(20);
然后将其分配给XAML image control:qrcodeimage.source = qrcodebitmapmap
给出了一个错误:
错误CS0029无法将类型'System.Drawing.BitMap'转换为 'microsoft.ui.xaml.media.imagesource'
,显然仍然需要一些转换。
我设法找到的所有文档和示例说明了如何从文件中打印图像,而不是位图对象。
如何在Winui 3应用中显示此代码生成的位图?
I want to display QR code generated by QRCoder library ( https://github.com/codebude/QRCoder/ ) in my WinUI 3 desktop app.
From QRCoder I get System.Drawing.Bitmap
object:
QRCodeGenerator qrCodeGenerator = new();
QRCodeData qrCodeData = qrCodeGenerator.CreateQrCode(associateSoftwareTokenResponse.SecretCode, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new(qrCodeData);
Bitmap qrCodeBitmap = qrCode.GetGraphic(20);
Then assigning it to XAML Image control: qrCodeImage.Source = qrCodeBitmap
gives an error:
Error CS0029 Cannot implicitly convert type 'System.Drawing.Bitmap' to
'Microsoft.UI.Xaml.Media.ImageSource'
So apparently there is still some conversion needed.
All documentation and examples I managed to find explain how to print an image from file but not Bitmap object.
How can I display this code generated Bitmap in my WinUI 3 app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够从类似的流中创建
bitmapimage
:You should be able to create a
BitmapImage
from a stream something like this: