-
Hi, I need to generate a QR code on the fly that is displayed on a web page using a base64 data string, i.e.:
Using const int widthPixels = 150;
const int heightPixels = 150;
const string qrCodeContent = "https://www.example.com";
BarcodeWriter qrWriter = new()
{
Format = BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions
{
Height = heightPixels,
Width = widthPixels,
Margin = 0,
},
};
using SKBitmap qrCode = qrWriter.Write(qrCodeContent);
using SKImage skImage = SKImage.FromBitmap(qrCode);
using SKData encoded = skImage.Encode(SKEncodedImageFormat.Png, 100);
var imageData = Convert.ToBase64String(encoded.AsSpan()); This does generate a QR code that displays properly. Are there any problems with this approach? Can it be improved or optimized in any way? Thank you, Jon |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Do you really need this line here? |
Beta Was this translation helpful? Give feedback.
Do you really need this line here?
using SKImage skImage = SKImage.FromBitmap(qrCode);
Isn't it possible to use qrCode directly?
using SKData encoded = qrCode.Encode(SKEncodedImageFormat.Png, 100);