2013-04-13 123 views
1

我想在asp.net中截取Div元素的截圖並將其保存到磁盤。我不想使用html2canvas庫或html5 canvas元素。方法可以是服務器端或客戶端。在asp.net中的div截圖

+0

你怎麼在DIV持有? –

+0

div包含一些文字和圖片... – pgmanutd

+0

請求訪問者截取屏幕截圖並上傳它不符合您的要求? :-P(只是爲了安全起見) –

回答

1

未經檢驗的,但發現這一點:

public Bitmap GenerateScreenshot(string url, int width, int height) 
{ 
    // Load the webpage into a WebBrowser control 
    WebBrowser wb = new WebBrowser(); 
    wb.ScrollBarsEnabled = false; 
    wb.ScriptErrorsSuppressed = true; 
    wb.Navigate(url); 
    while (wb.ReadyState != WebBrowserReadyState.Complete) 
    { 
     Application.DoEvents(); 
    } 

    // Set the size of the WebBrowser control 
    wb.Width = width; 
    wb.Height = height; 

    if (width == -1) 
    { 
     // Take Screenshot of the web pages full width 
     wb.Width = wb.Document.Body.ScrollRectangle.Width; 
    } 

    if (height == -1) 
    { 
     // Take Screenshot of the web pages full height 
     wb.Height = wb.Document.Body.ScrollRectangle.Height; 
    } 

    // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control 
    Bitmap bitmap = new Bitmap(wb.Width, wb.Height); 
    wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height)); 
    wb.Dispose(); 

    return bitmap; 
} 

http://pietschsoft.com/post/2008/07/c-generate-webpage-thumbmail-screenshot-image.aspx

+0

我已經通過這段代碼....它是一個基於Windows窗體的函數webbrowser類是存在於system.windows.forms命名空間...並在asp.net中使用Windows窗體將是一個壞主意......無論如何感謝回覆...更多的建議,歡迎:)...我是仍然感到困惑omegle是如何做同樣的事情...喜歡這個鏈接[鏈接](http://logs.omegle.com/f1d8ace) – pgmanutd

+0

你幾乎肯定會需要第三方。 http://phantomjs.org/似乎是最好的支持。只需要一個exe文件。 –

+0

有一些線程的考慮,但加載WebBrowser控件在asp.net中工作得很好。我自己也用過類似的東西。 – LouD