Asp.Net教程,WinForm教程,Asp.Net MVC,vs2008教程,vs2010教程,Silverlight技术,源码下载,Asp.Net视频教程
全站热门标签
vs2010 Silverlight 存储过程 水晶报表 LINQ ADO.NET JavaScript DataGridView GridView AjaxPro DevExpress 面向对象 Extjs XML HTML教程 Oracle jQuery WPF MVC 分页 Office2010 GDI+ Visual C++2010 Dojo MySQL VB.NET WCF4.0 ASPxGridView WinForm textbox Sql2005 cookie Discuz!NT checkbox WCF SQL经典语句 T-SQL F# asp.net VS2008 SQL Ajax DropDownList VS2008新特性 TreeView Access Flex 页面执行时间 字符串 DataSet VB2005 回调 动画 C#时间 游戏 ASP.NET MVC
尚未分类 LINQ教程 Enterprise技术 性能优化/调试 水晶报表与打印 安全与加密图形图像 文件处理 基础教程 Web Services 内置对象 控件示例 正则表达式\采集 ADO.NET 缓存\泛型\线程 XML技术 Url重写\静态页 vs2008综合教程
当前位置: 主页 > ASP.NET教程 > 图形图像 >

Asp.net网页截图的实现方法

时间:2010-02-03 23:27来源:未知 作者:admin 点击:

 

源代码如下:
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace Snap
{
    public class GetImage
    {
        int S_Height;
        int S_Width;
        int F_Height;
        int F_Width;
        string MyURL;
        public int ScreenHeight
        {
            get
            {
                return S_Height;
            }
            set
            {
                S_Height = value;
            }
        }
        public int ScreenWidth
        {
            get
            {
                return S_Width;
            }
            set
            {
                S_Width = value;
            }
        }
        public int ImageHeight
        {
            get
            {
                return F_Height;
            }
            set
            {
                F_Height = value;
            }
        }
        public int ImageWidth
        {
            get
            {
                return F_Width;
            }
            set
            {
                F_Width = value;
            }
        }
        public string WebSite
        {
            get
            {
                return MyURL;
            }
            set
            {
                MyURL = value;
            }
        }
        public GetImage(string WebSite, int ScreenWidth, int ScreenHeight, int ImageWidth, int ImageHeight)
        {
            this.WebSite = WebSite;
            this.ScreenHeight = ScreenHeight;
            this.ScreenWidth = ScreenWidth;
            this.ImageHeight = ImageHeight;
            this.ImageWidth = ImageWidth;
        }
        public Bitmap GetBitmap()
        {
            WebPageBitmap Shot = new WebPageBitmap(this.WebSite, this.ScreenWidth, this.ScreenHeight);
            Shot.GetIt();
            Bitmap Pic = Shot.DrawBitmap(this.ImageHeight, this.ImageWidth);
            return Pic;
        }
    }
    public class WebPageBitmap
    {
        WebBrowser MyBrowser;
        string URL;
        int Height;
        int Width;
        public WebPageBitmap(string url, int width, int height)
        {
            this.URL = url;
            this.Width = width;
            this.Height = height;
            MyBrowser = new WebBrowser();
            MyBrowser.ScrollBarsEnabled = false;
            MyBrowser.Size = new Size(this.Width, this.Height);
        }
        public void GetIt()
        {
            MyBrowser.Navigate(this.URL);
            while (MyBrowser.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }
        }
        public Bitmap DrawBitmap(int theight, int twidth)
        {
            Bitmap myBitmap = new Bitmap(this.Width, this.Height);
            Rectangle DrawRect = new Rectangle(0, 0, this.Width, this.Height);
            MyBrowser.DrawToBitmap(myBitmap, DrawRect);
            System.Drawing.Image imgOutput = myBitmap;
            System.Drawing.Bitmap oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat);
            Graphics g = Graphics.FromImage(oThumbNail);
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            Rectangle oRectangle = new Rectangle(0, 0, twidth, theight);
            g.DrawImage(imgOutput, oRectangle);
            try
            {
                return oThumbNail;
            }
            catch
            {
                return null;
            }
            finally
            {
                imgOutput.Dispose();
                imgOutput = null;
                MyBrowser.Dispose();
                MyBrowser = null;
            }
        }
    }
}
调用方法
                GetImage thumb = new GetImage(url, 1024, 768, 320, 240);
                System.Drawing.Bitmap x = thumb.GetBitmap();
                x.Save(Response.OutputStream, ImageFormat.Jpeg);
                Response.ContentType = "image/jpeg";
Tags:Asp.net网页截图
责任编辑:admin
返回顶部
------分隔线----------------------------
推荐内容
骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价 骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价
  • .Net实现PictureBox重叠透明效果

    关于一般的透明效果,这里不多说,相信很多人都会,这种透明效果一般需要设置父控件,是子控件相对于父控件的透明。那么很多人可能更为关心的是多个控件之间的透明效果,比...

  • C#图形处理系列(二)——雾化处理

    本系列专题前两篇分别探讨了常见的几种图形处理算法和性能已经图形的灰度处理、逆反处理和二值化处理,本文介绍雾化处理。 设想你有块透明的玻璃,朝上面哈几口气,然后将...

  • C#图形处理系列(一)——最简单第一步:逆反处理、二值处理

    在本系列博文中,将介绍几种常见的图形处理算法。上文 C#图片处理常见方法性能比较 中以彩色转灰色处理为例探讨了3中方法的性能,因此彩色转灰度处理就不再另做介绍。...

  • C#图形处理系列(三)——霓虹处理、浮雕处理

    霓虹处理与浮雕处理算法有共同之处,都是像素及邻近像素直接关系运算,因此放到一起写。 霓虹处理 关于霓虹灯的效果,不知道的可以baidu图片里面看看。 霓虹处理算...

  • 绘制几何图形:使用android.graphics类

    如何在和机上绘制2D图形呢?这是许多android游戏开发都是常提到的问题,在android SDK 当中,并没有Java Graphics2D的函数可以使用,...

  • .Net下二进制形式的文件(图片)的存储与读取

    看到标题,二进制形式的文件是很广的。这里我主要谈谈图片以二进制形式的数据读取和存储。 .Net下图片的常见存储与读取凡是有以下几种: 存储图片:以二进制的形式存...

  • C#图片验证码破解

    1 public class GetImageValue 2 { 3 // 设定图片RGB字符串 4 string []ArrayList = new stri...

  • ASP.NET画图系列之实现Curve图(曲线图)

    ASP.NET画图系列,今天要实现的是Curve图,如果各位朋友有什么不明白的可以留言或Email给我,我的Email:gfreesky@gmail.com 废...

  • ASP.NET画图系列之实现Bar图(柱状图)

    前面已经实现了Pie和Curve图,今天我们来实现Bar,就是柱状图,这个的实现和前面2种基本上差不多,还是让我们先看看效果再说. 效果图: 下面开始页面部分:...

  • ASP.NET画图系列之实现Pie图(圆饼图)

    ASP.NET自身提供的画图功能也是很强大的,在实际的项目中有时也会经常用到的,实现这样的功能方法很多,诸如水晶报表之类也可以实现,但有时我们只想实现单一的某些...

  • ASP.NET 2.0 HttpHandler实现生成图片验证码(示例代码下载)

    学习整理了一下 (一).功能 用HttpHandler实现图片验证码 (二).代码如下 1. 处理程序文件 ValidateImageHandler.ashx代...

  • 两种获取灰度图像的方法

    在图像处理程序开发中,常会遇到将一幅彩色图像转换成灰度图像的情况,笔者在最近的一个项目中便遇到了这点。经过一翻努力最终解决,想想有必要分享一下,于是便写下此文。...

  • Asp.net网页截图的实现方法

    源代码如下: using System; using System.Drawing; using System.Drawing.Imaging; using S...

  • ASP.NET图片渐变轮换效果

    一.静态的 HTML HEAD title图片渐变轮换效果/title meta name=generator content=editplus meta na...

  • ASP.NET添加水印(从Discuz!Nt挖出来的)

    这是从 Discuz!Nt 挖出来的代码 添加水印的强大代码。功能很强大。可以添加图片水印和文字水印两种 编写也很好。添加进去的效果非常好。 供大家欣赏 现在就...

  • ASP.NET2.0图片格式转换

    第一步:打开页面 第二步:选择一副Jpg格式的图片 第三步:转换为GIF格式,明显看出图片画质降低。 后台代码: using System; using Sys...

  • 添加文字水印类代码

    usingSystem; usingSystem.Collections.Generic; usingSystem.Text; usingSystem.Draw...

  • ASP.NET生成随机验证码示例

    常用的生成验证码程序,图片效果如下: 源程序如下: using System; using System.Drawing; using System.Drawi...