在webform中,如何将一个html页面的源代码转为为一张图片?

解决方案 »

  1.   

     public void ProcessRequest(HttpContext context)
            {
                //建立模板
                Bitmap bitmap = new Bitmap(46, 22);
                //设置画板颜色,建立画布
                Graphics g = Graphics.FromImage(bitmap);
                //填充背景色
                g.FillRectangle(Brushes.Gray, 0, 0, 46, 22);
                //生成随机字符串的范围
                string letters = "0123456789";
                //定义变量存储生成的验证码
                StringBuilder sb = new StringBuilder();
                //定义变量,存储生成的单个字符
                string result = string.Empty;
                //定义随机量
                Random rd = new Random();
                //设置字体
                Font f = new Font("宋体", 14);
                //添加到画布中
                              result ="你的源码";
                    g.DrawString(result, f, Brushes.White,10, rd.Next(0, 5));
                    sb.Append(result);
                
                //向响应流输出
                context.Response.ContentType = "Image/Jpg";
                //向输出流保存
                bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                //释放资源
                bitmap.Dispose();
                g.Dispose();
                context.Response.End();
            }