我想根据用户数据创建二维码。我使用下面的库来创建二维码。
Install-Package QRCoder
现在我已经完成了将数据转换为 base64 字符串的代码。
private static Byte[] BitmapToBytes(Bitmap img)
{
using (MemoryStream stream = new MemoryStream())
{
img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
return stream.ToArray();
}
}
public JsonResult SaveVisitorEntry(string FirstName, string LastName)
{
//VisitorEntryDA pdm = new VisitorEntryDA();
object obj = "";//pdm.getCity(country_id, Convert.ToInt64(state_id));
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(FirstName + " " + LastName, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);
ImageConverter converter = new ImageConverter();
return Json(JsonConvert.SerializeObject(BitmapToBytes(qrCodeImage)));
}
下面是我的 AJAX 代码,我将 Base64 转换为图像并将我的二维码显示为图像。
jQuery.ajax({
url: "../VisitorEntry/SaveVisitorEntry",
type: "POST",
//data: "{function:'" + value + "'}",
data: "{FirstName:'" + FirstName + "',LastName:'" + LastName + "'}",
dataType: "json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function (data) {
debugger
jQuery("#wait").css("display", "none");
toastr['success']('Line Stoppage closed Successfully');
//var results = JSON.parse(data);
//if (results.length == 0) {
// jQuery("#wait").css("display", "none");
//} else {
// f_group_data = results.Table;
// bindDropDown("function_name", f_group_data, "FUNCTION", "FUNCTION", "Select");
// jQuery('#function_name').chosen();
// jQuery('#function_name').trigger("chosen:updated");
// jQuery("#wait").css("display", "none");
//}
QrCodeImage.setAttribute('src', "data:image/jpg;base64," + data);
//setTimeout(function () {// wait for 5 secs(2)
// location.reload(); // then reload the page.(3)
//}, 3000);
},
error: function (data) {
jQuery("#wait").css("display", "none");
console.log("error");
}
});
我没有得到正确的 base64 字符串格式,并且在控制台中出现以下错误。
Failed to load resource: net::ERR_INVALID_URL
我得到的数据变量低于值
""iVBORw0KGgoAA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mmNNup3rdGGaY02ntwabZjidIMSPUrTGm08uTXaMK3RRv2uNdowrdHGk1ujDVOcblCiR2lao40nt0YbpjXaqN+1RhumNdp4cmu0YYrTDUr0KE1rtPHk1mjDtEYb9bvWaMO0RhtPbo02THG6QYkepWmNNp7cGm2Y1mijftcabZjWaOPJrdGGKU43KNGjNK3RxpNbow3TGm3U71qjDdMabTy5NdowxekGJXqUpjXaeHJrtGFao436XWu0YVqjjSe3RhumON2gRI/StEYbT26NNkxrtFG/a402TGu08eTWaMMUpxuU6FGa1mjjya3RhmmNNup3rdGGaY02ntwabZjidIMSPUrTGm08uTXaMK3RRv2uNdowrdHGk1ujDVOcblCiR2lao40nt0YbpjXaqN+1RhumNdp4cmu0YYrTDUr0KE1rtPHk1mjDtEYb9bvWaMO0RhtPbo02THG6QYkepWmNNp7cGm2Y1mijftcabZjWaOPJrdGGKU43KNGjNK3RxpNbow3TGm3U71qjDdMabTy5NdowxekGJXqUpjXaeHJrtGFao436XWu0YVqjjSe3RhumON2gRI/StEYbT26NNkxrtFG/a402TGu08eTWaMMUpxuU6FGa1mjjya3RhmmNNup3rdGGaY02ntwabZjidIMSPUrTGm08uTXaMK3RRv2uNdowrdHGk1ujDVOcblCiR2lao40nt0YbpjXaMK3RhmmNNkxrtGFao40nt0YbpjjdoESP0rRGG09ujTZMa7RhWqMN0xptmNZow7RGG09ujTZMcbpBiR6laY02ntwabZjWaMO0RhumNdowrdGGaY02ntwabZjidIMSPUrTGm08uTXaMK3RhmmNNkxrtGFaow3TGm08uTXaMMXpBiV6lKY12nhya7RhWqMN0xptmNZow7RGG6Y12nhya7RhitMNSvQoTWu08eTWaMO0RhumNdowrdGGaY02TGu08eTWaMMUpxuU6FGa1mjjya3RhmmNNkxrtGFaow3TGm2Y1mjjya3RhilONyjRozSt0caTW6MN0xptmNZow7RGG6Y12jCt0caTW6MNU5xuUKJHaVqjjSe3RhumNdowrdGGaY02TGu0YVqjjSe3RhumON2gRI/StEYbT26NNkxrtGFaow3T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nD6B9Z03V0ZtN1dOZ6TrmlL5L8YfSPrOk6OrPpOjpzPafc0hdJ/jD6R9Z0HZ3ZdB2duZ5TbumLJH8Y/SNruo7ObLqOzlzPKbf0RZI/jP6RNV1HZzZdR2eu55Rb+iLJH0b/yJquozObrqMz13PKLX2R5A+jf2RN19GZTdfRmes55Za+SPKH0T+ypu…"
答案 0 :(得分:0)
您在问题中提供的 base64 值格式不正确,我的建议是不要在此 Api 响应工作中使用 Json 序列化。
尝试使用 Convert.ToBase64String
string
text
为 dataType
响应。public IActionResult SaveVisitorEntry(string FirstName, string LastName)
{
...
return Ok(Convert.ToBase64String(BitmapToBytes(qrCodeImage)));
}
jQuery.ajax({
dataType: "text",
success: function (data) {
QrCodeImage.setAttribute('src', "data:image/jpg;base64," + data);
}
});
contentType
的更正,应该是 dataType
,它被更改为处理请求的响应。虽然我不确定这是否与您在此处观察到的问题有关,但我确实认为 data
请求负载应该是 object
,而不是 string
。< /p>
...
type: "POST",
data: {
FirstName: FirstName,
LastName: LastName
},
dataType: "text",
...
您还应该考虑处理 Api 端点中 Firstname
和 Lastname
参数均为 null
、空格或 string.Empty
的情况。
我也想string.Trim()
在这里作为理智的努力:qrGenerator.CreateQrCode($"{FirstName} {LastName}".Trim(), QRCodeGenerator.ECCLevel.Q);