我必须在网页上显示QR码,然后从ViewData获取QR码,该ViewData包含如下位图图像(50 * 50)地址
QRCodeGenerator qrGenerator = new QRCodeGenerator();
var qrGeneratedDateTime =Convert.ToString(DateTime.Now);
var code = Convert.ToString(valueVariable+ qrGeneratedDateTime);
QRCodeData qrCodedata = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodedata);
Bitmap bitMap= new Bitmap(50,50);
using (bitMap = qrCode.GetGraphic(20))
{
bitMap.Save(ms, ImageFormat.Png);
ViewData["QRCodeImage"] = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
}
但是,当网页上显示的QR码图像具有小表格(QR码显示之前)时,该表格中容纳QR码图像,则占据了几乎完整的窗口尺寸表,这表明位图图像采用了默认图像尺寸;我的代码中有什么错误。我想要自己的身高和宽度的QR码图像。
答案 0 :(得分:0)
我这样做是为了调整QR /条形码的大小:
private System.Drawing.Image ResizeImage(System.Drawing.Image image, int size)
{
System.Drawing.Image resizedImage = new Bitmap(size, size);
using (Graphics graphicsHandler = Graphics.FromImage(resizedImage))
{
graphicsHandler.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphicsHandler.DrawImage(image, 0, 0, size, size);
}
return resizedImage;
}