代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C#
】
获取网站缩略图
作者:
睿智
/ 发布于
2016/4/7
/
767
Form1.cs 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; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void 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(this.textBox1.Text)) { if (string.IsNullOrEmpty(this.textBox2.Text)) { MessageBox.Show("请选择要保存的目录!"); return; } if (string.IsNullOrEmpty(this.textBox3.Text)) { MessageBox.Show("请输入要保存的文件名!"); return; } try { GetWebImage gwi = new GetWebImage(this.textBox1.Text, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, 320, 240); Bitmap bi = gwi.GetBitmap(); bi.Save(this.textBox2.Text.Trim() + "\\" + this.textBox3.Text.Trim()); System.Diagnostics.Process.Start(this.textBox2.Text.Trim()+"\\"+this.textBox3.Text.Trim()); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("请输入正确的网址!"); return; } } private void button2_Click(object sender, EventArgs e) { folderBrowserDialog1.ShowDialog(this); this.textBox2.Text = folderBrowserDialog1.SelectedPath; } } } 另外还在启动时做了特别处理。。。。看代码: Program.cs 1 /* * 作者:HJL * 获取网站缩略图程序 * 2010年8月最后一天 * 欢迎修改和传播 * 最好能保留该信息^_^ * 也欢迎大家访问我的博客 * Http://www.528s.com/ */ using System; using System.Collections.Generic; using System.Windows.Forms; using Utility; using System.Drawing; using System.Text.RegularExpressions; namespace WindowsFormsApplication1 { static class Program { /// <summary> /// 应用程序的主入口点。 ///ex: a.exe www.cnblogs.com c:\\ a.bmp 320 340 on /// </summary> [STAThread] static void Main(string[] args) { if (args.Length == 6) { Regex r = new Regex(@"http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"); if (r.IsMatch(args[0])) { try { GetWebImage gwi = new GetWebImage(args[0], 1024, 768, Convert.ToInt32(args[3]), Convert.ToInt32(args[4])); Bitmap bi = gwi.GetBitmap(); bi.Save(args[1] + "\\" + args[2]); if (args[5].Equals("on")) { System.Diagnostics.Process.Start(args[1] + "\\" + args[2]); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("参数不正确,如:http://www.cnblogs.com/xt_hjl c:\\ a.bmp 320 240 on"); } return; } else if (args.Length > 0) { MessageBox.Show("参数不够,如:http://www.cnblogs.com/xt_hjl c:\\ a.bmp 320 240 on"); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } 引用到的代码/* * 修改者:吴鹏(AlphaWu) * Blog:Http://AlphaWu.CoM * 获取网站缩略图代码 * 2006 圣诞节 * C#代码根据该页面“http://www.codeproject.com/useritems/website_screenshot.asp” * VB.Net代码修改而来 * 欢迎修改和传播 * 最好能保留该信息^_^ * 也欢迎大家访问我的博客 * Http://AlphaWu.Cnblogs.CoM * * Http://AlphaWu.CoM * * */ using System; using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; namespace Utility { /// <summary> /// GetImage thumb = new GetImage(url, 1024, 768, 320, 240); //System.Drawing.Bitmap x = thumb.GetBitmap(); //x.Save(Response.OutputStream, ImageFormat.Jpeg); //Response.ContentType = "image/jpeg"; /// </summary> public class GetWebImage { int S_Height; int S_Width; int F_Height; int F_Width; 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; } } /// <summary> /// Initializes a new instance of the <see cref="GetWebImage"/> class. /// </summary> /// <param name="WebSite">The web site.</param> /// <param name="ScreenWidth">Width of the screen.</param> /// <param name="ScreenHeight">Height of the screen.</param> /// <param name="ImageWidth">Width of the image.</param> /// <param name="ImageHeight">Height of the image.</param> public GetWebImage(string WebSite, int ScreenWidth, int ScreenHeight, int ImageWidth, int ImageHeight) { this.WebSite = WebSite; this.ScreenHeight = ScreenHeight; this.ScreenWidth = ScreenWidth; this.ImageHeight = ImageHeight; this.ImageWidth = ImageWidth; } /// <summary> /// Gets the bitmap. /// </summary> /// <returns></returns> 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; } } /// <summary> /// /// </summary> public class WebPageBitmap { WebBrowser MyBrowser; string URL; int Height; int Width; /// <summary> /// Initializes a new instance of the <see cref="WebPageBitmap"/> class. /// </summary> /// <param name="url">The URL.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> public WebPageBitmap(string url, int width, 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); } /// <summary> /// Gets it. /// </summary> public void GetIt() { MyBrowser.Navigate(this.URL); while (MyBrowser.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } } /// <summary> /// Draws the bitmap. /// </summary> /// <param name="theight">The theight.</param> /// <param name="twidth">The twidth.</param> /// <returns></returns> 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.Image imgOutput = myBitmap; System.Drawing.Bitmap oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat); Graphics g = Graphics.FromImage(oThumbNail); g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; Rectangle oRectangle = new Rectangle(0, 0, twidth, theight); g.DrawImage(imgOutput, oRectangle); try { return oThumbNail; } catch { return null; } finally { imgOutput.Dispose(); imgOutput = null; MyBrowser.Dispose(); MyBrowser = null; } } } }
试试其它关键字
缩略图
同语言下
.
C#实现的html内容截取
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
去除字符串中的空格,回车,换行符转变成‘;’在按‘
.
按照回车换行符分割字符串
.
文件MD5码 比较,检测文件是否一样
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
睿智
贡献的其它代码
(
12
)
.
实现Oracle数据库备份
.
批量生成手机号码
.
根据当前文字选择返回被选中的文字
.
限制Textarea文本域字符个数
.
命令行CMD颜色设置
.
一个简单的Doctor类的封装
.
矩阵
.
获取网站缩略图
.
SQL查询一张表插入到另一张表
.
标签自适应高度和宽度
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3