获取其它网站页面到当前主机的内存中,将这个网页在内存中生成图片并存为文件,现在我遇到一个难题,就是怎样把抓取的网页生成为图片,哪位高手能给个思路或者代码,不胜感激.

解决方案 »

  1.   

    @Red_angelX(八戒) 
    非常感谢你的帮助,不过我找到的htmltoimage是用C/C++写的,我希望能用到asp.net/C#里,以便生成选择的网页,因此我需要C#的源码或思路自己写,请问哪位还知道有别的方法吗?
      

  2.   

    百度上的今天在 http://dotnetjunkies.com/WebLog/alan.dean/archive/2005/04/25/70496.aspx 看到了另外一种方法:通过IE截图
    private void OnDocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
    {
         using (Graphics srcGraphics = this.axWebBrowser1.CreateGraphics())
         {
              using (Graphics destGraphics = this.pictureBox1.CreateGraphics())
              {
                   IntPtr hdcDest = destGraphics.GetHdc();
                   IntPtr hdcSrc = srcGraphics.GetHdc();
                   GDI32.BitBlt(
                        hdcDest,
                        0, 0,
                        this.axWebBrowser1.ClientRectangle.Width, this.axWebBrowser1.ClientRectangle.Height,
                        hdcSrc,
                        0, 0,
                        (int) GDI32.TernaryRasterOperations.SRCCOPY
                        );
                   srcGraphics.ReleaseHdc(hdcSrc);
                   destGraphics.ReleaseHdc(hdcDest);
              }
         }

     
      

  3.   

    网上有一个PDFABC的东东,支持网页生成PDF,其中好你包括图片,但不是免费的。
      

  4.   

    //生成图片的网页有如下代码        
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
            newBitmap.Save(ms, ImageFormat.Jpeg);
            //输出图片
            Response.ClearContent();
            Response.ContentType = "image/gif";
            Response.BinaryWrite(ms.ToArray());
      

  5.   

    晕,点空格居然自动提交了
    重新写
            //生成图片的网页有如下代码
            //生成图片的代码
            /* 省略 */
            //将图片写入Response
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //将开始生成的图片保存
            newBitmap.Save(ms, ImageFormat.Jpeg);
            //输出图片
            Response.ClearContent();
            Response.ContentType = "image/gif";
            Response.BinaryWrite(ms.ToArray());
    //比如这个网页名字是1.aspx
    则其他页面调用他时将url属性设为~/1.aspx就可以了