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

C#实现网页截图功能相关推荐

  1. html网页截图功能支持svg图片保存

    根据自己的需求选取对应代码片段,可以节省50%的时间. 现在用到最多的页面截取插件就是html2canvas.将页面转化为canvas进行保存 但是为了兼容支持svg页面的截图,会先将svg页面转化成 ...

  2. Chrome网页截图功能

    第1步:F12  (打开开发者工具) 第2步:Ctrl+Shift+P (呼出查找框) 第3步:选择Capture full size screenshot(保存当前完整网页为图片)

  3. 浏览器-在网页中使用自定义截图功能

    总结一下目前了解到的网页截图功能实现 一 dom-to-image 1 npm地址: https://www.npmjs.com/package/dom-to-image 2 介绍: dom-to-i ...

  4. php 应用截图,PHP应用:php使用CutyCapt实现网页截图保存的方法

    <PHP应用:php使用CutyCapt实现网页截图保存的方法>要点: 本文介绍了PHP应用:php使用CutyCapt实现网页截图保存的方法,希望对您有用.如果有疑问,可以联系我们. 本 ...

  5. 前端如何实现一键截图功能?

    精彩回顾 有点意思的gif动图生成平台开发实战(二) 如何实现H5可视化编辑器的实时预览和真机扫码预览功能 在线IDE开发入门之从零实现一个在线代码编辑器 基于React+Koa实现一个h5页面可视化 ...

  6. Python实现网页截图,附带完整代码

    Python实现网页截图,附带完整代码 在现代化的互联网时代,我们经常需要对网页进行截图以便于保存.共享以及其他种种用途.Python是一种功能强大的编程语言,可以帮助我们轻松地实现网页截图功能.本文 ...

  7. php 网页截屏,php使用CutyCapt实现网页截图保存的方法

    本文实例讲述了php使用CutyCapt实现网页截图保存的方法.分享给大家供大家参考,具体如下: 网页截图这个功能大家可能用到最多的就是QQ截图,或利用asp.net来实现截图,其实我们也可以直接使用 ...

  8. 猛犸全网页截图:牛人又出牛应用

    亲,还记得那个给了谈微创新的大佬们一记响亮耳光的季逸超吗?没错,就是那个独自开发出猛犸浏览器并获得Macworld2011特等奖的北大附中学生.现在,这头"小牛"又给大家带来一款超 ...

  9. android截取网页图片,安卓版谷歌浏览器很快将获得滚动截图功能 可以用来截取整个网页...

    截图功能对用户来说应该是非常常用的功能,然而有时候截取网页时可能需要我们进行多次截图再拼接截图图片. 为解决这种问题现在已经有些软件提供滚动截图功能,滚动截图可帮助用户一次性将整个网页内容截图无需拼接 ...

最新文章

  1. Verilog设计实例(4)详解全类别加法器(一)
  2. Shell中的数据重定向--输入/输出重定向
  3. 回溯法(深度优先)剪枝和分支限界法(宽度优先)剪枝对比:01背包问题
  4. elasticsearch使用more_like_this实现基于内容的推荐
  5. =======================================以前的======================================
  6. c++基础学习(08)--(继承、重载、多态、虚函数)
  7. Java文档阅读笔记-JPA Tutorial
  8. 检测到在集成的托管管道模式下不适用的ASP.NET设置
  9. activemq mysql 配置详解_activeMQ数据库配置
  10. javascript(定时函数)
  11. win10启动修复_在win10桌面建立高级启动选项快捷方式,修复电脑故障不用愁
  12. DS18B20 引脚 定义 单总线 多点温度检测 STM32 单片机
  13. 基于Python实现的网上购书功能的网站后端
  14. 第十六届全国大学生智能车竞赛创意组获奖名单 | 带有学生与指导教师信息
  15. dataframe分组并求平均
  16. 电脑开机太慢?这5个方法瞬间提升你的电脑速度
  17. linux执行可执行命令程序ls,linux运行可执行程序命令
  18. iOS App托管和分发搭建
  19. 分享一下自己的手机从ios14降级回ios13.5.1,可以保存资料哦
  20. Python实现将人脸表情数据集fer2013转化为图像形式存储本地

热门文章

  1. springboot整合swagger2之最佳实践
  2. 2022-2028年中国操作系统行业深度调研及投资前景预测报告
  3. 手撸一个JdbcTemplate,带你了解其原理
  4. Windows10+Anaconda3+Pycharm环境搭建
  5. 深度神经网络混合精度训练
  6. 噪声标签的负训练:ICCV2019论文解析
  7. 2021年大数据常用语言Scala(三十八):scala高级用法 隐式转换和隐式参数
  8. Cocos 物理系统
  9. 零起点学算法10——求圆柱体的表面积
  10. 如何把手变成手控_在这个模拟手的VR游戏里,你能体验到很多手控福利