C#生成二维码

 /// <summary>
        /// 生成二维码 !
        /// </summary>
        /// <param name="context"></param>
        public static void GetQode(HttpContext context)
        {
            string url = context.Request["url"];
            string Newurl = HttpUtility.UrlDecode(url);
            Bitmap bt;
            QRCodeEncoder code = new QRCodeEncoder();
            bt = code.Encode(Newurl, Encoding.UTF8);using (Bitmap objBitmap = bt)
            {
                if (objBitmap != null)
                {
                    

                    using (MemoryStream objMS = new MemoryStream())
                    {
                        objBitmap.Save(objMS, ImageFormat.Jpeg);

                        HttpContext.Current.Response.ClearContent();
                        HttpContext.Current.Response.ContentType = "image/Jpeg";
                        HttpContext.Current.Response.BinaryWrite(objMS.ToArray());
                        HttpContext.Current.Response.Flush();
                        HttpContext.Current.Response.End();
                    }
                }
            }

        }



 

posted @ 2016-11-30 10:07  方金  阅读(1437)  评论(0编辑  收藏  举报