C# 二维码在线生成

    void CreateUrlQRCodeIMG()
    {
        Response.Cache.SetCacheability(HttpCacheability.Public);
        Response.Cache.SetMaxAge(TimeSpan.FromSeconds(600000));

        Response.ContentType = "image/gif";

        string link = Request.QueryString["url"] ?? string.Empty;
        if (string.IsNullOrEmpty(link))
        {
            return;
        }
        link = HttpUtility.UrlDecode(link);

        QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
        QrCode qrCode = qrEncoder.Encode(link);
        GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(8, QuietZoneModules.Four), Brushes.Black, Brushes.White);
        renderer.WriteToStream(qrCode.Matrix, ImageFormat.Gif, Response.OutputStream);

    }

 

posted @ 2019-03-11 14:41  AlexLeeLi  阅读(429)  评论(0编辑  收藏  举报