How do you take a Screenshot of a website via .Net code?

前端 未结 4 897
别跟我提以往
别跟我提以往 2020-12-09 05:08

Is it possible to take a screen shot of any given url using .Net code?

What is the easiest way to do it?

4条回答
  •  不思量自难忘°
    2020-12-09 05:08

    I searched far and wide to find a solution to this problem and the issue with using the WebBrowser and other suggestions is that you need a lot of access to the box.

    To date this is the best third party tool I have been able to find:

    http://www.websitesscreenshot.com/

    Their SEO is terrible, but I believe I found them on a forum or even Stack... I do own a license and what you get is just a single DLL you can reference. Passing a license to the constructor removes their watermark.

    After a quick peek with ILSpy I believe what it does is that it interprets the HTML and dumps an image for your viewing pleasure.

    Usage

    Saving A URL

    WebsitesScreenshot.WebsitesScreenshot  _Obj;
    _Obj = new WebsitesScreenshot.WebsitesScreenshot ();
    WebsitesScreenshot.WebsitesScreenshot.Result _Result;
    _Result = _Obj.CaptureWebpage("http://www.google.com");
    if (_Result == WebsitesScreenshot.WebsitesScreenshot.Result.Captured)
    {
        _Obj.ImageFormat = WebsitesScreenshot.
            WebsitesScreenshot.ImageFormats.PNG;
        _Obj.SaveImage ("c:\\google.png");
    }            
    _Obj.Dispose();
    

    Saving Raw HTML String

    WebsitesScreenshot.WebsitesScreenshot _Obj;
    _Obj=new WebsitesScreenshot.WebsitesScreenshot();
    WebsitesScreenshot.WebsitesScreenshot.Result _Result;
    _Result = _Obj.CaptureHTML(
    "

    Hello world

    "); if (_Result == WebsitesScreenshot.WebsitesScreenshot.Result.Captured) { _Obj.ImageFormat = WebsitesScreenshot. WebsitesScreenshot.ImageFormats.GIF; _Obj.SaveImage("c:\\test.gif"); } _Obj.Dispose();

    You can find more on their usage page. Found Here:

    http://www.websitesscreenshot.com/Usage.html

    Hope this helps !

    Cheers!!

提交回复
热议问题