How can I programmatically create a screen shot of a given Web site?
Asked Answered
E

7

11

I want to be able to create a screen shot of a given Web site, but the Web site may be larger than can be viewed on the screen. Is there a way I can do this?

Goal is to do this with .NET in C# in a WinForms application.

Equestrian answered 17/4, 2009 at 20:53 Comment(1)
There is someone that wants to do this as a server-side script, but I need a WinForms application.Equestrian
Z
8

There are a few tools.

The thing is, you need to render it in some given program, and take a snapshot of it. I don't know about .NET but here are some tools to look at.

Zestful answered 17/4, 2009 at 20:56 Comment(0)
C
2

I just found out about the website browsershots.org which generates screenshots for a whole bunch of different browsers. To a certain degree you can even specify the resolution.

Communication answered 17/4, 2009 at 21:3 Comment(0)
M
1

I wrote a program in VB.NET that did what you specified, except for the screen size issue.

I embedded a web control(look at the very bottom of all controls) onto my form, and tweaked it's settings(Hide scroll). I used a timer to wait on dynamic content, and then I used "copyFromScreen" to get the image.

My program had dynamic dimensions(settable via command line). I found that if I made my program larger than the screen, the image would just return black pixels for the off screen area. I did not research farther since my job was complete at that time.

Hope that gives you a good start. Sorry for any wrong wordings. I log onto windows to develop only once every couple of months.

Maelstrom answered 17/4, 2009 at 21:3 Comment(0)
M
0

Doing at as a screen shot is likely to get ugly. It's easy enough to capture the entire content of the page with wget, but the image means capturing the rendering.

Here's some tools that purport to do it.

Mouser answered 17/4, 2009 at 20:57 Comment(0)
P
0

This is the code for creating screenshot programatically:


using System.Drawing.Imaging;


int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
bmpScreenShot.Save("test.jpg", ImageFormat.Jpeg);

Plexus answered 21/5, 2009 at 5:29 Comment(1)
-1 That's a screenshot of the users desktop, not of a websiteDesulphurize
A
0

You can render it on WebBrowser control and then take snapshot if page size bigger than screen size you have to scroll control take one or more snapshots and then merge all pictures :)

Alcock answered 15/7, 2009 at 22:6 Comment(0)
A
0

Java ScreenShots of WebSite

Combine Screens together for Final Entire WebPage Screenshot.

public static void main(String[] args) throws FileNotFoundException, IOException {
        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
        ChromeDriver browser = new ChromeDriver();  
        WebDriver driver = browser;
        driver.get("https://news.google.co.in/");
        driver.manage().timeouts().implicitlyWait(500, TimeUnit.SECONDS);

        JavascriptExecutor jse = (JavascriptExecutor) driver;
        Long clientHeight = (Long) jse.executeScript("return document.documentElement.clientHeight");
        Long scrollHeight = (Long) jse.executeScript("return document.documentElement.scrollHeight");
        int screens = 0, xAxis = 0, yAxis = clientHeight.intValue();
        String screenNames = "D:\\Screenshots\\Yash";
        for (screens = 0; ; screens++) {
            if (scrollHeight.intValue() - xAxis < clientHeight) {
                File crop = new File(screenNames + screens+".jpg");
                FileUtils.copyFile(browser.getScreenshotAs(OutputType.FILE), crop);                 

                BufferedImage image = ImageIO.read(new FileInputStream(crop));            
                int y_Axixs = scrollHeight.intValue() - xAxis;
                BufferedImage croppedImage = image.getSubimage(0, image.getHeight()-y_Axixs, image.getWidth(), y_Axixs);
                ImageIO.write(croppedImage, "jpg", crop);               
                break;
            }               

FileUtils.copyFile(browser.getScreenshotAs(OutputType.FILE), new File(screenNames + screens+".jpg")); 
 jse.executeScript("window.scrollBy("+ xAxis +", "+yAxis+")");

                jse.executeScript("var elems = window.document.getElementsByTagName('*');"                              
                        + "     for(i = 0; i < elems.length; i++) { "
                        + "         var elemStyle = window.getComputedStyle(elems[i], null);"
                        + "         if(elemStyle.getPropertyValue('position') == 'fixed' && elems[i].innerHTML.length != 0 ){"                                                                  
                        + "             elems[i].parentNode.removeChild(elems[i]); "                                
                        + "}}");    // Sticky Content Removes
                xAxis += yAxis;
        }
        driver.quit();
    }
Adallard answered 6/7, 2015 at 5:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.