QRCode 如何產生

  • 2142
  • 0

摘要:QRCode 如何產生

前置作業

首先要在 NuGet 安裝 Qr Code library

QRCode.aspx

只要加入


QRCode.aspx.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using MessagingToolkit.QRCode.Codec;
using MessagingToolkit.QRCode.Codec.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

public partial class QRCode_QRCode : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string LocalPath = Request.PhysicalApplicationPath + "QRCode\\";
        
        //建立資料夾
        if (!Directory.Exists(LocalPath))
        {
            Directory.CreateDirectory(LocalPath);
        }

        //QRCODE 產生器
        QRCodeEncoder encoder = new QRCodeEncoder();
        Bitmap img = encoder.Encode(Request.Url.AbsoluteUri);   //將目前的網頁路徑轉成QRCode
        img.Save(LocalPath + "QRCode.jpg", ImageFormat.Jpeg);
        QRImage.ImageUrl = "~/QRCode/" + "QRCode.jpg";
    }
}

 

各位客官看看,ASP.NET 不難的碑

我是 ASP.NET 新手,程式有問題再請告知喔!!