Enter any URL. generate an image of the webpage opened by the URL.
GetImage class
Public class GetImage
{
Private int S_Height;
Private int S_Width;
Private int F_Height;
Private int F_Width;
Private string MyURL;
Public int ScreenHeight
{
Get {return S_Height ;}
Set {S_Height = value ;}
}
Public int ScreenWidth
{
Get {return S_Width ;}
Set {S_Width = value ;}
}
Public int ImageHeight
{
Get {return F_Height ;}
Set {F_Height = value ;}
}
Public int ImageWidth
{
Get {return F_Width ;}
Set {F_Width = value ;}
}
Public string WebSite
{
Get {return MyURL ;}
Set {MyURL = value ;}
}
Public GetImage (string WebSite, int ScreenWidth, int ScreenHeight, int ImageWidth, int ImageHeight)
{
This. WebSite = WebSite;
This. ScreenWidth = ScreenWidth;
This. ScreenHeight = ScreenHeight;
This. ImageHeight = ImageHeight;
This. ImageWidth = ImageWidth;
}
Public Bitmap GetBitmap ()
{
WebPageBitmap Shot = new WebPageBitmap (this. WebSite, this. ScreenWidth, this. ScreenHeight );
Shot. GetIt ();
Bitmap Pic = Shot. DrawBitmap (this. ImageHeight, this. ImageWidth );
Return Pic;
}
}
Class WebPageBitmap
{
WebBrowser MyBrowser;
String URL;
Int Height;
Int Width;
Public WebPageBitmap (string url, int width, int height)
{
This. Height = height;
This. Width = width;
This. URL = url;
MyBrowser = new WebBrowser ();
MyBrowser. ScrollBarsEnabled = false;
MyBrowser. WebBrowserShortcutsEnabled = false;
MyBrowser. ObjectForScripting = false;
MyBrowser. Size = new Size (this. Width, this. Height );
}
Public void GetIt ()
{
MyBrowser. Navigate (this. URL );
While (MyBrowser. ReadyState! = WebBrowserReadyState. Complete)
{
Application. DoEvents ();
}
}
Public Bitmap DrawBitmap (int theight, int twidth)
{
Bitmap myBitmap = new Bitmap (Width, Height );
Rectangle DrawRect = new Rectangle (0, 0, Width, Height );
MyBrowser. DrawToBitmap (myBitmap, DrawRect );
System. Drawing. Image imgOutput = myBitmap;
System. Drawing. Image oThumbNail = new Bitmap (twidth, theight, imgOutput. PixelFormat );
Graphics g = Graphics. FromImage (oThumbNail );
G. CompositingQuality = CompositingQuality. HighSpeed;
G. SmoothingMode = SmoothingMode. HighSpeed;
G. InterpolationMode = InterpolationMode. HighQualityBilinear;
Rectangle orectangle = new Rectangle (0, 0, twidth, theight );
G. DrawImage (imgOutput, orectangle );
Try
{
Return (Bitmap) oThumbNail;
}
Catch (Exception ex)
{
Console. WriteLine (ex. Message );
Return null;
}
Finally
{
ImgOutput. Dispose ();
ImgOutput = null;
MyBrowser. Dispose ();
MyBrowser = null;
}
}
}
Public class OLayer
{
Public void CaptureImage (string url)
{
System. Drawing. Bitmap x = null;
Try
{
// String url = "http: //" + Request. Url. Host + ":" + Request. Url. Port. ToString ();
// Url = url + UrlPath;
// GetImage thumb = new GetImage (url, 1024,320 0, 1024,320 0 );
// Generate the length, width, and height of the page Image
GetImage thumb = new GetImage (url, 1024,800 0, 1024,800 0 );
X = thumb. GetBitmap ();
String FileName = DateTime. Now. ToString ("yyyyMMddhhmmss ");
// X. Save (System. Environment. CurrentDirectory + "\ cap \" + FileName + ". jpg ");
X. Save (System. Environment. CurrentDirectory + FileName + ". jpg ");
// CaptureState = true;
}
Catch (Exception ex)
{
MessageBox. Show (ex. ToString ());
// CaptureState = false;
}
Finally
{
If (x! = Null) x. Dispose ();
}
}
}
Page call:
OLayer ow = new OLayer();
ow.CaptureImage(tstr[i].ToString());