Screen shot of website


We can take the screen shot of the website by using the following code

We can create the screen shot of the website using "System.Drawing.Image"
and a webBrowser control

Namespace part


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.IO;
using System.Runtime.InteropServices;



Coding Part

webBrowser1.Navigate("http://www.dotnetspider.com");
Bitmap MyBitmap = new Bitmap(1024, 768);
Rectangle MyRectancle = new Rectangle(0, 0, 1024, 768);

webBrowser1.DrawToBitmap(MyBitmap, MyRectancle);

System.Drawing.Image MyorigImage = MyBitmap;
System.Drawing.Image MyorigThumbnail = new Bitmap(120,90, MyorigImage.PixelFormat);
Graphics MyGraphics = Graphics.FromImage(MyorigThumbnail);
MyGraphic.CompositingQuality = CompositingQuality.HighQuality;
MyGraphic.SmoothingMode = SmoothingMode.HighQuality;
MyGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
Rectangle MyORectangle = new Rectangle(0, 0, 120, 90);
oGraphic.DrawImage(MyorigImage, MyORectangle);

MyorigThumbnail.Save("DNSScreenshot.png", ImageFormat.Png);
MyorigImage.Dispose();



1. Navigate the website using webBrowser Control
2. Using the System.Drawing.Image, Generate a thumbnail of the screenshot
3. Save the file in PNG format


By
Nathan


Comments

Author: Felice28 Dec 2010 Member Level: Bronze   Points : 1

Hi,
I was looking exactly for a snipet like this!
Thank you.
I am a biginner in coding and I have experienced some problem with your code.
I had errors on the following lines:

MyGraphic.CompositingQuality = CompositingQuality.HighQuality;
MyGraphic.SmoothingMode = SmoothingMode.HighQuality;
MyGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;

These three rows of code should be MyGraphics.......

same problem here:

oGraphic.DrawImage(MyorigImage, MyORectangle);

oGraphic do not exsist! This also should be MyGraphics.DrawImage(MyorigImage, MyORectangle);

I hope is correct but in any case the saved image is blank and this means that there is aproblem somwhere.

I would appreciate your advices.

Thanks
Felice

Author: Hemal03 Jan 2011 Member Level: Bronze   Points : 0

Nice Post

http://asp-code-bank.blogspot.com/p/windows-intellisense.html



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: