二維碼生成與返回客戶端

引用

QRCoder

示例代碼

<img src="/Controller/GetImg"/>
public ActionResult GetImg()
{
    string authorizeUrl="";
    string authorizeCode = Guid.NewGuid().ToString();

    //生成二維碼
    string url = $"{authorizeUrl}?authorizeCode={authorizeCode}";
    QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
    QRCodeData qrCodeData = qrGenerator.CreateQrCode(url, QRCodeGenerator.ECCLevel.Q);
    QRCode qrcode = new QRCode(qrCodeData);
    Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false);
    MemoryStream ms = new MemoryStream();
    qrCodeImage.Save(ms, ImageFormat.Jpeg);
    return File(ms.ToArray(), "image/jpeg");
}

參考資料

angular-cli server - how to proxy API requests to another server?
C# 生成二維碼 QRCoderhtml

相關文章
相關標籤/搜索