Search code examples
c#screenshotcutycaptiecapt

Programmatically get a screenshot of a page


I'm writing a specialized crawler and parser for internal use, and I require the ability to take a screenshot of a web page in order to check what colours are being used throughout. The program will take in around ten web addresses and will save them as a bitmap image.

From there I plan to use LockBits in order to create a list of the five most used colours within the image. To my knowledge, it's the easiest way to get the colours used within a web page, but if there is an easier way to do it please chime in with your suggestions.

Anyway, I was going to use ACA WebThumb ActiveX Control until I saw the price tag. I'm also fairly new to C#, having only used it for a few months. Is there a solution to my problem of taking a screenshot of a web page in order to extract the colour scheme?


Solution

  • https://screenshotlayer.com/documentation is the only free service I can find lately...

    You'll need to use HttpWebRequest to download the binary of the image. See the provided url above for details.

    HttpWebRequest request = HttpWebRequest.Create("https://[url]") as HttpWebRequest;
    Bitmap bitmap;
    using (Stream stream = request.GetResponse().GetResponseStream())
    {
        bitmap = new Bitmap(stream);
    }
    // now that you have a bitmap, you can do what you need to do...