// description of your code here
1
2 using System;
3 using System.Collections.Generic;
4 using System.Text;
5 using System.Drawing;
6 using System.Drawing.Drawing2D;
7 using System.Drawing.Imaging;
8 using System.Windows.Forms;
9 using System.Diagnostics;
10
11 namespace MyLib
12 {
13 public class GetImage
14 {
15 private int S_Height;
16 private int S_Width;
17 private int F_Height;
18 private int F_Width;
19 private string MyURL;
20
21 public int ScreenHeight
22 {
23 get { return S_Height; }
24 set { S_Height = value; }
25 }
26
27 public int ScreenWidth
28 {
29 get { return S_Width; }
30 set { S_Width = value; }
31 }
32
33 public int ImageHeight
34 {
35 get { return F_Height; }
36 set { F_Height = value; }
37 }
38
39 public int ImageWidth
40 {
41 get { return F_Width; }
42 set { F_Width = value; }
43 }
44
45 public string WebSite
46 {
47 get { return MyURL; }
48 set { MyURL = value; }
49 }
50
51 public GetImage(string WebSite, int ScreenWidth, int ScreenHeight, int ImageWidth, int ImageHeight)
52 {
53 this.WebSite = WebSite;
54 this.ScreenWidth = ScreenWidth;
55 this.ScreenHeight = ScreenHeight;
56 this.ImageHeight = ImageHeight;
57 this.ImageWidth = ImageWidth;
58 }
59
60 public Bitmap GetBitmap()
61 {
62 WebPageBitmap Shot = new WebPageBitmap(this.WebSite, this.ScreenWidth, this.ScreenHeight);
63 Shot.GetIt();
64 Bitmap Pic = Shot.DrawBitmap(this.ImageHeight, this.ImageWidth);
65 return Pic;
66 }
67 }
68
69 class WebPageBitmap
70 {
71 WebBrowser MyBrowser;
72 string URL;
73 int Height;
74 int Width;
75
76 public WebPageBitmap(string url, int width, int height)
77 {
78 this.Height = height;
79 this.Width = width;
80 this.URL = url;
81 MyBrowser = new WebBrowser();
82 MyBrowser.ScrollBarsEnabled = false;
83 MyBrowser.WebBrowserShortcutsEnabled = false;
84 MyBrowser.ObjectForScripting = false;
85
86 MyBrowser.Size = new Size(this.Width, this.Height);
87 }
88
89 public void GetIt()
90 {
91 MyBrowser.Navigate(this.URL);
92 while (MyBrowser.ReadyState != WebBrowserReadyState.Complete)
93 {
94 Application.DoEvents();
95 }
96 }
97
98 public Bitmap DrawBitmap(int theight, int twidth)
99 {
100 Bitmap myBitmap = new Bitmap(Width, Height);
101 Rectangle DrawRect = new Rectangle(0, 0, Width, Height);
102 MyBrowser.DrawToBitmap(myBitmap, DrawRect);
103 System.Drawing.Image imgOutput = myBitmap;
104 System.Drawing.Image oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat);
105 Graphics g = Graphics.FromImage(oThumbNail);
106 g.CompositingQuality = CompositingQuality.HighSpeed;
107 g.SmoothingMode = SmoothingMode.HighSpeed;
108 g.InterpolationMode = InterpolationMode.HighQualityBilinear;
109 Rectangle oRectangle = new Rectangle(0, 0, twidth, theight);
110 g.DrawImage(imgOutput, oRectangle);
111 try
112 {
113
114 return (Bitmap)oThumbNail;
115 }
116 catch (Exception ex)
117 {
118 Console.WriteLine(ex.Message);
119 return null;
120 }
121 finally
122 {
123 imgOutput.Dispose();
124 imgOutput = null;
125 MyBrowser.Dispose();
126 MyBrowser = null;
127 }
128 }
129
130 }
131 public class OLayer{
132 public void CaptureImage(string url){
133 System.Drawing.Bitmap x =null;
134
135 try{
136 // string url = "http://" + Request.Url.Host + ":" + Request.Url.Port.ToString();
137 //url = url + UrlPath;
138
139 GetImage thumb = new GetImage(url, 1024, 3200, 1024, 3200);
140 x = thumb.GetBitmap();
141 string FileName = DateTime.Now.ToString("yyyyMMddhhmmss");
142
143 x.Save( System.Environment.CurrentDirectory + "\\cap\\"+ FileName + ".jpg");
144 //CaptureState = true;
145 }catch (Exception ex){
146 Console.WriteLine( ex.ToString());
147 //CaptureState = false;
148 }finally{
149 if(x!=null) x.Dispose();
150 }
151 }
152 }
153 public class Run
154 { [STAThread]
155 public static void Main(){
156 OLayer ow=new OLayer();
157 ow.CaptureImage("http://www.5do8.com/");
158 }
159
160 }
161 }
162