<%@ WebHandler Language="C#" Class="Rcode" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Data;
using System.Text;
using EB_Common;
using EB_BLL;
using EB_Model;
using ThoughtWorks.QRCode.Codec;

public class Rcode : IHttpHandler {

    public void ProcessRequest (HttpContext context) {

        String absPath = context.Request.Url.AbsoluteUri;
        int lastIndex = absPath.LastIndexOf('/') + 1;
        String url = absPath.Substring(0,  lastIndex);
        CreateQrcode(context, String.Format("{0}weixin/Login.aspx",url));

    }

    private void CreateQrcode(HttpContext context,string nr)
    {
        Bitmap bt;
        string enCodeString = nr;
        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
        bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8);

        MemoryStream ms = new MemoryStream();
        bt.Save(ms, System.Drawing.Imaging.ImageFormat.Png);//把图像数据序列化到内存

        context.Response.ClearContent();
        context.Response.ContentType = "image/Png";
        context.Response.OutputStream.Write(ms.GetBuffer(), 0, (int)ms.Length);
        context.Response.BinaryWrite(ms.GetBuffer());
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}