当前位置: 首页 > 编程日记 > 正文

C#实现网页截图功能

  1. //需要添加System.Drawing及System.Windows.Forms引用
  2. using System;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Drawing.Imaging;
  6. using System.Windows.Forms;
  7. namespace 网页截图
  8. {
  9. class Program
  10. {
  11. [STAThread]
  12. static void Main(string[] args)
  13. {
  14. string url = "http://www.yongfa365.com/";
  15. MyLib.GetImage thumb = new MyLib.GetImage(url, 1024, 4000, 1024, 4000);
  16. System.Drawing.Bitmap x = thumb.GetBitmap();
  17. string FileName = DateTime.Now.ToString("yyyyMMddhhmmss");
  18. x.Save(@"C:\" + FileName + ".jpg");
  19. Console.WriteLine("成功");
  20. Console.ReadKey();
  21. }
  22. }
  23. }
  24. namespace MyLib
  25. {
  26. public class GetImage
  27. {
  28. private int S_Height;
  29. private int S_Width;
  30. private int F_Height;
  31. private int F_Width;
  32. private string MyURL;
  33. public int ScreenHeight
  34. {
  35. get { return S_Height; }
  36. set { S_Height = value; }
  37. }
  38. public int ScreenWidth
  39. {
  40. get { return S_Width; }
  41. set { S_Width = value; }
  42. }
  43. public int ImageHeight
  44. {
  45. get { return F_Height; }
  46. set { F_Height = value; }
  47. }
  48. public int ImageWidth
  49. {
  50. get { return F_Width; }
  51. set { F_Width = value; }
  52. }
  53. public string WebSite
  54. {
  55. get { return MyURL; }
  56. set { MyURL = value; }
  57. }
  58. public GetImage(string WebSite, int ScreenWidth, int ScreenHeight, int ImageWidth, int ImageHeight)
  59. {
  60. this.WebSite = WebSite;
  61. this.ScreenWidth = ScreenWidth;
  62. this.ScreenHeight = ScreenHeight;
  63. this.ImageHeight = ImageHeight;
  64. this.ImageWidth = ImageWidth;
  65. }
  66. public Bitmap GetBitmap()
  67. {
  68. WebPageBitmap Shot = new WebPageBitmap(this.WebSite, this.ScreenWidth, this.ScreenHeight);
  69. Shot.GetIt();
  70. Bitmap Pic = Shot.DrawBitmap(this.ImageHeight, this.ImageWidth);
  71. return Pic;
  72. }
  73. }
  74. class WebPageBitmap
  75. {
  76. WebBrowser MyBrowser;
  77. string URL;
  78. int Height;
  79. int Width;
  80. public WebPageBitmap(string url, int width, int height)
  81. {
  82. this.Height = height;
  83. this.Width = width;
  84. this.URL = url;
  85. MyBrowser = new WebBrowser();
  86. MyBrowser.ScrollBarsEnabled = false;
  87. MyBrowser.Size = new Size(this.Width, this.Height);
  88. }
  89. public void GetIt()
  90. {
  91. MyBrowser.Navigate(this.URL);
  92. while (MyBrowser.ReadyState != WebBrowserReadyState.Complete)
  93. {
  94. Application.DoEvents();
  95. }
  96. }
  97. public Bitmap DrawBitmap(int theight, int twidth)
  98. {
  99. Bitmap myBitmap = new Bitmap(Width, Height);
  100. Rectangle DrawRect = new Rectangle(0, 0, Width, Height);
  101. MyBrowser.DrawToBitmap(myBitmap, DrawRect);
  102. System.Drawing.Image imgOutput = myBitmap;
  103. System.Drawing.Image oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat);
  104. Graphics g = Graphics.FromImage(oThumbNail);
  105. g.CompositingQuality = CompositingQuality.HighSpeed;
  106. g.SmoothingMode = SmoothingMode.HighSpeed;
  107. g.InterpolationMode = InterpolationMode.HighQualityBilinear;
  108. Rectangle oRectangle = new Rectangle(0, 0, twidth, theight);
  109. g.DrawImage(imgOutput, oRectangle);
  110. try
  111. {
  112. return (Bitmap)oThumbNail;
  113. }
  114. catch (Exception ex)
  115. {
  116. return null;
  117. }
  118. finally
  119. {
  120. imgOutput.Dispose();
  121. imgOutput = null;
  122. MyBrowser.Dispose();
  123. MyBrowser = null;
  124. }
  125. }
  126. }
  127. }

转载于:https://www.cnblogs.com/liufei88866/archive/2010/06/22/1762657.html

相关文章:

微软发布全新多核心操作系统原型:Barrelfish

Windows 7完成之后,很多人开始把目光投向微软的下一代服务器和客户端操作系统Windows 8,不过今天微软放出了一套全新操作系统的原型,开发代号“Barrelfish”。该系统由微软剑桥研究院和苏黎世理工学院联合全新开发,专为现在和未来…

Docker应用:Kubernetes(容器集群)

Docker应用:Kubernetes(容器集群) 原文:Docker应用:Kubernetes(容器集群)阅读目录: Docker应用:Hello WorldDocker应用:Docker-compose(容器编排)…

通道应用——抠头发

通道应用——抠头发 原图: 效果图: 步骤:1、打开原图的“通道面板”,选择颜色对比分明的绿色通道,并新建一个绿色通道副本;2、选择“图像”-“调整”-“色阶”,调节色阶使得头发颜色更分明些&am…

2017 ACM/ICPC 南宁赛区小结 By JSB @ Reconquista

Statistics TYPE: Onsite ContestNAME: 2017 - ICPC - Asia NanningPLAT: pc^2TIME: 2017/11/26 09:00-14:00LOCA: Guangxi UniversityTEAM: Reconquista[shb,lsmll,jsb]RANK: 8/227 3.52%SOLVE: 8/13PENALTY: 451 ◦ A - 1 ◦ E - 123 (2) ◦ F - 8 ◦ H - 55 ◦ I - 97 (1) ◦…

用户管理系统控制台版连接数据库

建User表 CREATE TABLE user (id INT(11) NOT NULL AUTO_INCREMENT,name VARCHAR(20) DEFAULT NULL,pwd VARCHAR(20) DEFAULT NULL,PRIMARY KEY (id) ) ENGINEINNODB AUTO_INCREMENT5 DEFAULT CHARSETutf8User对象(javaBean) public class User {priva…

微信小程序组件 日历

js文件 use strict;let choose_year null,choose_month null;const conf {data: {hasEmptyGrid: false,showPicker: false},onLoad() {const date new Date();const cur_year date.getFullYear();const cur_month date.getMonth() 1;const weeks_ch [ 日, 一, 二, 三, …

node编写定时任务,for循环只执行一遍的解决办法

在用node编写定时任务时候,发现for循环只执行i0这一次,就不接着循环执行了,下面贴上代码: exports.task async function(ctx){ let { app } ctx, resultArr1 [],//查询的数据库数据 resultArr2 [];//查询的数据库…

oledb读不到dbf文件内容

最近在处理一批VFP的数据库,使用OleDB方式读取一直很正常,前两天突然碰到一张表怎么也读不出数据来,害我瞎忙了一整天,在研究了DBF文件结构后发现记录前的0x20位置存储的是0x2A。 一查才知道是删除标记,我倒&#xff0…

好用的截图工具

好用的截图工具...简单好用而且不大转载于:https://blog.51cto.com/dd123/208983

“AS3.0高级动画编程”学习:第二章转向行为(上)

因为这一章的内容基本上都是涉及向量的,先来一个2D向量类:Vector2D.as (再次强烈建议不熟悉向量运算的童鞋,先回去恶补一下高等数学-07章空间解释几何与向量代数.pdf) package {import flash.display.Graphics;public class Vector2D {privat…

用Azure VM + Azure Database for MySQL搭建Web服务

仍然是一篇动手实验,实验演示如何在Azure的虚拟机内部署一个Web服务器,并且使用Azure Mysql PaaS作为本应用的数据库。此实验的目的一方面是为了演示Azure IaaS层和PaaS服务配合使用的常规操作,另一方面是为之后的文章打基础,后续…

C3P0_and_pro.properties配置文档代码

C3P0-config.xml配置文件 <c3p0-config> <!-- 默认配置&#xff0c;如果没有指定则使用这个配置 --> <default-config><property name"driverClass">com.mysql.jdbc.Driver</property><property name"jdbcUrl">jdbc:…

电视信号——行场同步

电视信号分NTSC制和PAL制两种制式, NTSC制每秒刷新60次, 而PAL制每秒刷新50次。 水平消隐&#xff1a;电子枪从左到右画出象素&#xff0c;它每次只能画一条扫描线&#xff0c;画下一条之前要先回到左边并做好画下一条扫描线的准备&#xff0c;这之间有一段时间叫做水平消隐&am…

QWidget一生,从创建到销毁事件流

版权声明&#xff1a;若无来源注明&#xff0c;Techie亮博客文章均为原创。 转载请以链接形式标明本文标题和地址&#xff1a;本文标题&#xff1a;QWidget一生&#xff0c;从创建到销毁事件流 本文地址&#xff1a;http://techieliang.com/2017/11/319/ 代码较多&#xff…

事物_软件分层

事务 事务是&#xff1a;在数据库指业务处理的”一个业务“对应数据库中的多个步骤的操作。例如银行转账。 面对的问题&#xff1a;程序接受请求后&#xff0c;会至少发送两条SQL语句&#xff0c;两条语句之间会有时间的间隔&#xff0c;如果间隔时间期间Mysql服务器发生意外&a…

雷林鹏分享:jQuery EasyUI 数据网格 - 创建属性网格

jQuery EasyUI 数据网格 - 创建属性网格 属性网格(property grid)带有一个内置的 expand(展开)/collapse(合并) 按钮&#xff0c;可以简单地为行分组。您可以简单地创建一个可编辑属性的分层(hierarchical)列表。 设置 HTML url"propertygrid_data.json" showGroup&q…

as3.0中如何阻止事件冒泡?

as3.0中的事件冒泡机制有时候会很烦人&#xff0c;比如一个Sprite(方便下文描述就命名为Container吧)把另一外Sprite(称为Child吧)做为子元素套进来以后&#xff0c;如果两个Sprite都注册了Mouse_Down事件&#xff0c;要想在Child上点击鼠标时系统只响应Child的Mouse_Down事件&…

紫色回归线:雅虎中国的运筹学

共同体并不意味着一个我们可以获得享受的世界&#xff0c;而是一个我们热切希望栖息、希望重新拥有的世界。—— 齐格蒙特.鲍曼紫色回归线&#xff1a;雅虎中国的运筹学紫色是比较中性的颜色&#xff0c;但紫色在生活中却也是温柔、神秘、甚至性感的代词。当雅虎中国将主色调重…

JavaScript_上

javaScript JavaScript,简称JS&#xff0c;是Web开发中不可缺少的脚本语言的&#xff0c;不需要编译就可以运行&#xff08;解释性语言&#xff09;。它“寄生”在HTML体内&#xff0c;随网络传输到客户端在浏览器中运行。js代码可以写到html的任何地方。一般写在 body 结束标签…

java类加载的表现形式

java中的类是动态加载的&#xff0c;我们先看一下我们常用的类加载方式&#xff0c;先有一个感性的认识&#xff0c;才能进一步 深入讨论,类加载无非就是下面三种方式。 class A{} class B{} class C{} public class Loader{ public static void main(String[] args) throws Ex…

.net core在vs开发环境下脱离iis运行

.net core相比之前.net的是一个可以跨平台&#xff0c;脱离iis运行的语言&#xff0c;并且项目启动的效率要比用iis启动快&#xff0c;可以说进一步提高了开发的效率。要想自己的项目core脱离iis&#xff0c;首先选择vs启动项目的载体&#xff1a; 如下图&#xff0c;不要选择I…

Sublime遇见中文乱码问题?

今天在写demo的时候&#xff0c;突然发现html页面上的中文在浏览器上显示乱码~&#xff01;&#xff01;&#xff01;&#xff01;&#xff01; 这时&#xff0c;我根据网上的提示安装了两个插件:converttoUtf-8&#xff0c;support Gbk ~~~然而&#xff0c;好像无济于事~~ 于是…

Dynamics AX 2009 升级PreSynchnoize时的无反应的解决

问题: 安装完升级补丁后在Data upgrade cockpit窗口点击Run或Train Run按钮后Update Job没有开始&#xff0c;始终显示为Ready状态。 #1 原因&#xff1a;数据库以前已经做过升级&#xff08;例如安装过AX 2009 SP1&#xff09;并且已经存在一个DataUpdate批处理组但是针对这个…

如何 搭建 RMAN 备份平台

一&#xff0e; RMAN 的一些理论知识RMAN Catalog 和 Nocatalog 的区别http://blog.csdn.net/tianlesoftware/archive/2010/06/02/5641763.aspxRMAN 系列&#xff08;一&#xff09;---- RMAN 体系结构概述http://blog.csdn.net/tianlesoftware/archive/2010/06/09/5659701.asp…

git更新代码报错,error: The following untracked working tree files would be overwritten by ch

git忽略大小写导致的&#xff0c; git config --add core.ignorecase true 转载于:https://www.cnblogs.com/newcbs/p/10732662.html

JavaScript_下_Dom

Dom对象 Dom对象&#xff1a;Document Object Model 文档对象模型。js是用来操作html的。 一个文档必须被加载到浏览器中&#xff0c;会按照HTML的层级结构转换成一个“家谱树”称为dom树。HTML文档里的所以的标签&#xff0c;属性&#xff0c;文本都会转换成dom树上的节点。 …

HDU 4300 Clairewd’s message

一道KMP的变式 本题仍是求最大前缀后缀&#xff0c;所以仍用KMP&#xff0c;但不同的是&#xff0c;本题有一个密码转换规则&#xff0c;不过好在题目中说了两段不重合&#xff0c;那么我们就可以在中间插入一个特殊符号*&#xff0c;保证求next数组时不会越过中线&#xff0c;…

GNS3模拟VPC注意几点

网上的GNS3入门到精通视频的确做得不错。现我写一下主要几点&#xff1a;1、创建MS lookback 适配器在添加硬件那里&#xff0c;并注意IP设置要在本地网卡同一子网&#xff0c;网关不用设置的。2、GNS3 的Dynamips目录的cygwin1.dll文件替代VPCS目录中文件。3、GNS3中的模拟PC先…

Windows Phone 7 Tip (5) -- App liftcycle

在新的trainning kit 中有一个例子解释的很清楚了&#xff1a; 1. Application_Launching&#xff1a;只有在新启动程序时触发 2. Application_Closing&#xff1a;只有在推出程序时触发--只有在程序mainpage时按硬后退键 3. Application_Activated&#xff1a;从home键或者其它…

npm i和npm install的区别

最近人用npm i来直接安装模块&#xff0c;但是有会报错&#xff0c;用npm install就不会报错&#xff0c;刚开始百思不得其解&#xff0c;它俩明明是同一个东西后来查npm的帮助指令发现还是没区别&#xff0c;npm i仅仅是npm install的简写&#xff1a; 实际使用的区别点主要如…