Asp.net 如何创建网页的图像并使用.net将图像保存到服务器?

Asp.net 如何创建网页的图像并使用.net将图像保存到服务器?,asp.net,Asp.net,我有一个页面,动态生成一个小html页面,其中包含一个小表格w/文本。我希望能够拍摄该页面的图片(最好是png),并将其保存到我的服务器 我以前使用的是第三方解决方案(ABCdrawHTML2),但我已经更改了服务器,而这一个没有。没有第三方解决方案,有没有办法做到这一点?这是我使用Windows的方式。Forms WebBrowser: public class WebSiteThumbnailImage { string m_Url; int m_BrowserWidth,

我有一个页面,动态生成一个小html页面,其中包含一个小表格w/文本。我希望能够拍摄该页面的图片(最好是png),并将其保存到我的服务器


我以前使用的是第三方解决方案(ABCdrawHTML2),但我已经更改了服务器,而这一个没有。没有第三方解决方案,有没有办法做到这一点?

这是我使用Windows的方式。Forms WebBrowser:

public class WebSiteThumbnailImage
{
    string m_Url;
    int m_BrowserWidth, m_BrowserHeight, m_ThumbnailWidth, m_ThumbnailHeight;
    Bitmap m_Bitmap = null;

    public WebSiteThumbnailImage(string url, int browserWidth, int browserHeight, int thumbnailWidth, int thumbnailHeight)
    {
        m_Url = url;
        m_BrowserWidth = browserWidth;
        m_BrowserHeight = browserHeight;
        m_ThumbnailWidth = thumbnailWidth;
        m_ThumbnailHeight = thumbnailHeight;
    }

    public Bitmap GenerateWebSiteThumbnailImage()
    {
        Thread m_thread = new Thread(new ThreadStart(_GenerateWebSiteThumbnailImage));
        m_thread.SetApartmentState(ApartmentState.STA);
        m_thread.Start();
        m_thread.Join();
        return m_Bitmap;
    }

    private void _GenerateWebSiteThumbnailImage()
    {
        WebBrowser m_WebBrowser = new WebBrowser();
        m_WebBrowser.ScrollBarsEnabled = false;           
        m_WebBrowser.Navigate(m_Url);
        m_WebBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);

        while (m_WebBrowser.ReadyState != WebBrowserReadyState.Complete)          
            Application.DoEvents();

        m_WebBrowser.Dispose(); 
    }

    private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {            
        WebBrowser m_WebBrowser = (WebBrowser)sender;
        m_WebBrowser.ClientSize = new Size(this.m_BrowserWidth, this.m_BrowserHeight);
        m_WebBrowser.ScrollBarsEnabled = false;
        m_Bitmap = new Bitmap(m_WebBrowser.Bounds.Width, m_WebBrowser.Bounds.Height);
        m_WebBrowser.BringToFront();
        m_WebBrowser.DrawToBitmap(m_Bitmap, m_WebBrowser.Bounds);
        m_Bitmap = (Bitmap)m_Bitmap.GetThumbnailImage(m_ThumbnailWidth, m_ThumbnailHeight, null, IntPtr.Zero);
    }
}
要使用此功能,请在代码隐藏的适当位置执行以下操作:

WebSiteThumbnailImage thumbnail = new WebSiteThumbnailImage(url, 1000, 1000, 200, 200);
Bitmap image = thumbnail.GenerateWebSiteThumbnailImage();
image.Save(filePath);

谢谢,但是我对asp.net很陌生,不知道如何实现它。这像函数吗?如何添加要抓取的url或要保存的位置?很抱歉,我不知道我在做什么,但我正在努力快速学习。在过去的5年中,我一直在使用php。这是一个供您在aspx.cs代码中使用的类。在需要创建缩略图的地方,创建此类的实例,然后调用GenerateWebSiteThumbnailImage函数。它会传回一个位图,让您以您想要的任何格式保存。@AmazingChase抱歉,忘了ping。“这是一个供您在您的aspx.cs代码中使用的类。”我该如何确切地做到这一点?我很抱歉重复这个问题。我理解它的作用(看起来很完美),但我完全不知道如何调用它。当我将代码放入我的aspx页面时,我得到了一个编译错误:public关键字不可用作标识符。我只是不明白.net页面的语法。