打印

[.net] 求高手们一同研究在线生成网站截图的程序!

本主题由 kuhanzhu 于 2008-4-30 14:24 分类
http://www.browsrcamp.com/
直接说主题吧,这是个一能自己抓下网站,并且生成网站截图的网站!

我不知道他的原理是什么,更不知道他是怎么做到的!

来这里就是想问问这是怎么回事```,怎么做到的!

[之所以用这个站,是因为他比别的站还要好,不管网站被拉的多长,这个站都能一下子的全截下来,我测试过163的页面了!]

用Asp.net的程序写的成生截图,可不太看得懂


[ 本帖最后由 prince2pl 于 2008-4-29 20:16 编辑 ]
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!
在这里不太好意思的说,我现在只是ASP比较了解,PHP了解一般!所以,不能很好的读懂这个程序!
还希望,能人们能帮忙解读一下原理!

如果能改成ASP,或者PHP更好!,谢稿!
偶对 .net了解有限,但对那个截图程序也很有兴趣...
天助自助者!

回复 prince2pl 在 1# 的帖子

我也研究这个东西一段时间了

在线截图是运用服务器上的浏览环境,在线截取的
和你的服务器设置有关

.net相当耗资源,并且核心的代码没有开放

其实通过php gd库也可以实现这个功能

国内研究这个东西的很少人,在国外这个东西不是很少见。
www.fzlbar.com

TOP

还在为头像烦恼?还在为不能关注好友动态烦忧?快来蓝色理想家园吧!
我想听听这个要怎么做才可以呢?就一直没有高手知道这个事情吗?

TOP

我觉得这个应该在服务端编写自己的扩展

TOP

开放了核心代码的, 就这么点东西, 主要用到了 WebBrowser 和 GDI+ .

基本思路是, 在后台动态实例化一个 WebBrower 来加载需要的URL, 调用其 DrawToBitmap 来得到图像, 然后就是用 Graphics 生成图片。
修行的魔法师

TOP

如楼上所言,就是调用WebBrowser这个组件的。
复制内容到剪贴板
代码:
using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Drawing.Imaging;
  using System.Windows.Forms;
  using System.Diagnostics;
   
  namespace MyLib
  {
   public class GetImage
   {
   private int S_Height;
   private int S_Width;
   private int F_Height;
   private int F_Width;
   private 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.ScreenWidth = ScreenWidth;
   this.ScreenHeight = ScreenHeight;
   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;
   }
   }
   
   class WebPageBitmap
   {
   WebBrowser MyBrowser;
   string URL;
   int Height;
   int Width;
   
   public WebPageBitmap(string url, int width, int height)
   {
   this.Height = height;
   this.Width = width;
   this.URL = url;
   MyBrowser = new WebBrowser();
   MyBrowser.ScrollBarsEnabled = false;
   MyBrowser.WebBrowserShortcutsEnabled = false;
   MyBrowser.ObjectForScripting = 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(Width, Height);
       Rectangle DrawRect = new Rectangle(0, 0, Width, Height);
       MyBrowser.DrawToBitmap(myBitmap, DrawRect);
       System.Drawing.Image imgOutput = myBitmap;
       System.Drawing.Image oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat);
       Graphics g = Graphics.FromImage(oThumbNail);
       g.CompositingQuality = CompositingQuality.HighSpeed;
       g.SmoothingMode = SmoothingMode.HighSpeed;
       g.InterpolationMode = InterpolationMode.HighQualityBilinear;
       Rectangle oRectangle = new Rectangle(0, 0, twidth, theight);
       g.DrawImage(imgOutput, oRectangle);
       try
       {
       
       return (Bitmap)oThumbNail;
       }
       catch (Exception ex)
       {
        Console.WriteLine(ex.Message);
       return null;
       }
       finally
       {
       imgOutput.Dispose();
       imgOutput = null;
       MyBrowser.Dispose();
       MyBrowser = null;
       }
   }
   }
public class OLayer{
   public void CaptureImage(string url){
        System.Drawing.Bitmap x =null;
       try{
          // string url = "http://" + Request.Url.Host + ":" + Request.Url.Port.ToString();
           //url = url + UrlPath;
           
           GetImage thumb = new GetImage(url, 1024, 3200, 1024, 3200);
           x = thumb.GetBitmap();
           string FileName = DateTime.Now.ToString("yyyyMMddhhmmss");
           
           x.Save( System.Environment.CurrentDirectory + "\\cap\\"+ FileName + ".jpg");
           //CaptureState = true;
       }catch (Exception ex){
           Console.WriteLine(  ex.ToString());
           //CaptureState = false;
       }finally{
        if(x!=null) x.Dispose();
       }
   }  
}
public class Run
{        [STAThread]
        public static void Main(){
            OLayer ow=new OLayer();
            ow.CaptureImage("http://www.5do8.com/");
    }
}   
  }
我记得就是截取的只是第一屏。

你解决了全部的话记得告诉我。
23555455(WEB中高程Q群) 我的播客,去代码片断平台

TOP

具体的应用是什么呢?

TOP

原理就是国外的网站给出的核心源代码,http://www.codeproject.com/KB/IP/htmlimagecapture.aspx

这下这个是我写来测试的,在线截图
http://wangwolue.cn/websnap/
功能比较简单的,只是觉得好玩

TOP

很好,收藏下!
ML5X.CN

TOP

有那种asptophp的软件,懂php的话不妨转换一下了
我想学习

TOP

东西不错。做个记号,研究研究
大巧不工 大象无形
╭(︶_︶≠)╮

TOP

int DocumentHeight = MyBrowser.Document.Window.Size.Height;
            int DocumentWidth = MyBrowser.Document.Window.Size.Width;
            MyBrowser.Size = new Size(DocumentWidth, DocumentHeight);
            
这样MyBrowser的大小就是实际页面的大小了

不过我改的只能抓没有flash的页。真奇怪
大巧不工 大象无形
╭(︶_︶≠)╮

TOP