版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、获取网站缩略图代码先看界面效果图:最终运行得出的图如下:页面代码:* 最好能保留该信息_* 也欢迎大家访问我的博客* Http:/*/using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using Utility;using System.Threading;using System.Text.RegularExpressions;n
2、amespace WindowsFormsApplication1publicpartialclass Form1 : Formpublic Form1()InitializeComponent();privatevoid button1_Click(object sender, EventArgs e)if (string.IsNullOrEmpty(this.textBox1.Text)MessageBox.Show(请输入要截图的网址!);return;Regex r = new Regex(http:/(w-+.)+w-+(/w- ./?%&=*)?); if (r.IsMatch(t
3、his.textBox1.Text)if (string.IsNullOrEmpty(this.textBox2.Text)MessageBox.Show(请选择要保存的目录!);return;if (string.IsNullOrEmpty(this.textBox3.Text)MessageBox.Show(请输入要保存的文件名!);return;tryGetWebImage240);Bitmap bi = gwi.GetBitmap();bi.Save(this.textBox2.Text.Trim() + + this.textBox3.Text.Trim();System.Diagn
4、ostics.Process.Start(this.textBox2.Text.Trim()+this.textBox3.Text.Trim();catch (Exception ex)MessageBox.Show(ex.Message);elseMessageBox.Show(请输入正确的网址!);return;privatevoid button2_Click(object sender, EventArgs e)folderBrowserDialog1.ShowDialog(this);this.textBox2.Text = folderBrowserDialog1.Selected
5、Path;gwi = new GetWebImage(this.textBox1.Text, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, 320,另外还在启动时做了特别处理。看代码:5* 2010年8月最后一天6* 欢迎修改和传播7* 最好能保留该信息_8* 也欢迎大家访问我的博客9* Http:/10*11*/12 using System;13 using System.Collections.Generic;14 using System.Windows.Forms;15 using Uti
6、lity;16 using System.Drawing;17 using System.Text.RegularExpressions;1819 namespace WindowsFormsApplication12021staticclass Program2223/24/应用程序的主入口点。25/ex: a.exe c: a.bmp 320 340 on26/27 STAThread28staticvoid Main(string args)2930if (args.Length = 6)3132Regex r = new Regex(http:/(w-+.)+w-+(/w- ./?%&
7、=*)?);33if (r.IsMatch(args0)3435try3637GetWebImage gwi = new GetWebImage(args0, 1024, 768, Convert.ToInt32(args3), Convert.ToInt32(args4);38Bitmap bi = gwi.GetBitmap();39bi.Save(args1 + + args2);40if (args5.Equals(on)4142System.Diagnostics.Process.Start(args1 + + args2);43444546catch (Exception ex)4
8、748MessageBox.Show(ex.Message);495051else5253MessageBox.Show(参数不正确,如: c: a.bmp 320 240 on);545556return;5758elseif (args.Length 0)5960MessageBox.Show(参数不够,如: c: a.bmp 320 240 on);61return;6263Application.EnableVisualStyles(); 64Application.SetCompatibleTextRenderingDefault(false);65Application.Run(n
9、ew Form1();66676869*/using System;using System.Drawing;using System.Drawing.Imaging;using System.Windows.Forms;namespace Utility/ GetImage thumb = new GetImage(url, 1024, 768, 320, 240); /System.Drawing.Bitmap x = thumb.GetBitmap();/x.Save(Response.OutputStream, ImageFormat.Jpeg);/Response.ContentTy
10、pe = image/jpeg;/publicclass GetWebImageint S_Height;int S_Width;int F_Height;int F_Width;string MyURL;publicint ScreenHeightgetreturn S_Height;setS_Height = value;publicint ScreenWidthgetreturn S_Width;setS_Width = value;publicint ImageHeightgetreturn F_Height;setF_Height = value;publicint ImageWid
11、thgetreturn F_Width;setF_Width = value;publicstring WebSitegetreturn MyURL;setMyURL = value;/ Initializes a new instance of the class. /The web site./Width of the screen./Height of the screen./Width of the image./Height of the image.public GetWebImage(string WebSite, int ScreenWidth, int ScreenHeigh
12、t, int ImageWidth, int ImageHeight)this.WebSite = WebSite;this.ScreenHeight = ScreenHeight;this.ScreenWidth = ScreenWidth;this.ImageHeight = ImageHeight;this.ImageWidth = ImageWidth;/ Gets the bitmap./public Bitmap GetBitmap()WebPageBitmap Shot = new WebPageBitmap(this.WebSite, this.ScreenWidth, thi
13、s.ScreenHeight);Shot.GetIt();Bitmap Pic = Shot.DrawBitmap(this.ImageHeight, this.ImageWidth);return Pic;/publicclass WebPageBitmapWebBrowser MyBrowser;string URL;int Height;int Width;/ Initializes a new instance of the class. /The URL./The width./The height.public WebPageBitmap(string url, int width
14、, int height)this.URL = url;this.Width = width;this.Height = height;MyBrowser = new WebBrowser();MyBrowser.ScrollBarsEnabled = false;MyBrowser.Size = new Size(this.Width, this.Height);/ Gets it./publicvoid GetIt()MyBrowser.Navigate(this.URL);while (MyBrowser.ReadyState != WebBrowserReadyState.Comple
15、te)Application.DoEvents();/ Draws the bitmap./The theight./The twidth./public Bitmap DrawBitmap(int theight, int twidth)Bitmap myBitmap = new Bitmap(this.Width, this.Height);Rectangle DrawRect = new Rectangle(0, 0, this.Width, this.Height);MyBrowser.DrawToBitmap(myBitmap, DrawRect);System.Drawing.Im
16、age imgOutput = myBitmap;System.Drawing.BitmapimgOutput.PixelFormat);Graphics g = Graphics.FromImage(oThumbNail);g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;g.InterpolationModeSystem.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;=
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 麻醉药品和精神药品管理制度
- 骨科护理创新思维训练
- 呼吸困难护理的新进展
- 健康宣教应体现要点
- 2026年版思想道德与法治考试题及答案
- 糖尿病护理知识考核试题及答案解析
- 剑麻栽培工诚信评优考核试卷含答案
- 绢人工岗前规章考核试卷含答案
- 柔性版制版员常识测试考核试卷含答案
- 钽电解电容器赋能、被膜工安全理论强化考核试卷含答案
- 2026 年民政局认可离婚协议书正规模板
- PRP培训课件教学课件
- 桥梁悬臂浇筑施工技术标准
- 北京长城课件
- 医疗机构反家暴培训课件
- 危大工程巡视检查记录表(含基坑、支撑、脚手架、塔吊安拆工程)
- 租店面合同范本模板
- GB 7691-2025涂装作业安全管理通则
- 2025年职业技能鉴定考试(汽车驾驶员高级)题库及答案
- 数字文化产品国际化传播策略体系构建
- 2025年湖北省高考物理真题卷含答案解析
评论
0/150
提交评论