日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

C#实现网页截图功能

發布時間:2023/11/27 生活经验 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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. ??
  8. ??
  9. namespace?網頁截圖 ??
  10. { ??
  11. ????class?Program ??
  12. ????{ ??
  13. ????????[STAThread] ??
  14. ????????static?void?Main(string[]?args) ??
  15. ????????{ ??
  16. ????????????string?url?=?"http://www.yongfa365.com/"; ??
  17. ????????????MyLib.GetImage?thumb?=?new?MyLib.GetImage(url,?1024,?4000,?1024,?4000); ??
  18. ????????????System.Drawing.Bitmap?x?=?thumb.GetBitmap(); ??
  19. ????????????string?FileName?=?DateTime.Now.ToString("yyyyMMddhhmmss"); ??
  20. ??
  21. ????????????x.Save(@"C:\"?+?FileName?+?".jpg"); ??
  22. ????????????Console.WriteLine("成功"); ??
  23. ????????????Console.ReadKey(); ??
  24. ????????} ??
  25. ????} ??
  26. } ??
  27. ??
  28. ??
  29. ??
  30. ??
  31. ??
  32. namespace?MyLib ??
  33. { ??
  34. ????public?class?GetImage ??
  35. ????{ ??
  36. ????????private?int?S_Height; ??
  37. ????????private?int?S_Width; ??
  38. ????????private?int?F_Height; ??
  39. ????????private?int?F_Width; ??
  40. ????????private?string?MyURL; ??
  41. ??
  42. ????????public?int?ScreenHeight ??
  43. ????????{ ??
  44. ????????????get?{?return?S_Height;?} ??
  45. ????????????set?{?S_Height?=?value;?} ??
  46. ????????} ??
  47. ??
  48. ????????public?int?ScreenWidth ??
  49. ????????{ ??
  50. ????????????get?{?return?S_Width;?} ??
  51. ????????????set?{?S_Width?=?value;?} ??
  52. ????????} ??
  53. ??
  54. ????????public?int?ImageHeight ??
  55. ????????{ ??
  56. ????????????get?{?return?F_Height;?} ??
  57. ????????????set?{?F_Height?=?value;?} ??
  58. ????????} ??
  59. ??
  60. ????????public?int?ImageWidth ??
  61. ????????{ ??
  62. ????????????get?{?return?F_Width;?} ??
  63. ????????????set?{?F_Width?=?value;?} ??
  64. ????????} ??
  65. ??
  66. ????????public?string?WebSite ??
  67. ????????{ ??
  68. ????????????get?{?return?MyURL;?} ??
  69. ????????????set?{?MyURL?=?value;?} ??
  70. ????????} ??
  71. ??
  72. ????????public?GetImage(string?WebSite,?int?ScreenWidth,?int?ScreenHeight,?int?ImageWidth,?int?ImageHeight) ??
  73. ????????{ ??
  74. ????????????this.WebSite?=?WebSite; ??
  75. ????????????this.ScreenWidth?=?ScreenWidth; ??
  76. ????????????this.ScreenHeight?=?ScreenHeight; ??
  77. ????????????this.ImageHeight?=?ImageHeight; ??
  78. ????????????this.ImageWidth?=?ImageWidth; ??
  79. ????????} ??
  80. ??
  81. ????????public?Bitmap?GetBitmap() ??
  82. ????????{ ??
  83. ????????????WebPageBitmap?Shot?=?new?WebPageBitmap(this.WebSite,?this.ScreenWidth,?this.ScreenHeight); ??
  84. ????????????Shot.GetIt(); ??
  85. ????????????Bitmap?Pic?=?Shot.DrawBitmap(this.ImageHeight,?this.ImageWidth); ??
  86. ????????????return?Pic; ??
  87. ????????} ??
  88. ????} ??
  89. ??
  90. ????class?WebPageBitmap ??
  91. ????{ ??
  92. ????????WebBrowser?MyBrowser; ??
  93. ????????string?URL; ??
  94. ????????int?Height; ??
  95. ????????int?Width; ??
  96. ??
  97. ????????public?WebPageBitmap(string?url,?int?width,?int?height) ??
  98. ????????{ ??
  99. ????????????this.Height?=?height; ??
  100. ????????????this.Width?=?width; ??
  101. ????????????this.URL?=?url; ??
  102. ????????????MyBrowser?=?new?WebBrowser(); ??
  103. ????????????MyBrowser.ScrollBarsEnabled?=?false; ??
  104. ????????????MyBrowser.Size?=?new?Size(this.Width,?this.Height); ??
  105. ????????} ??
  106. ??
  107. ????????public?void?GetIt() ??
  108. ????????{ ??
  109. ????????????MyBrowser.Navigate(this.URL); ??
  110. ????????????while?(MyBrowser.ReadyState?!=?WebBrowserReadyState.Complete) ??
  111. ????????????{ ??
  112. ????????????????Application.DoEvents(); ??
  113. ????????????} ??
  114. ????????} ??
  115. ??
  116. ????????public?Bitmap?DrawBitmap(int?theight,?int?twidth) ??
  117. ????????{ ??
  118. ????????????Bitmap?myBitmap?=?new?Bitmap(Width,?Height); ??
  119. ????????????Rectangle?DrawRect?=?new?Rectangle(0,?0,?Width,?Height); ??
  120. ????????????MyBrowser.DrawToBitmap(myBitmap,?DrawRect); ??
  121. ????????????System.Drawing.Image?imgOutput?=?myBitmap; ??
  122. ????????????System.Drawing.Image?oThumbNail?=?new?Bitmap(twidth,?theight,?imgOutput.PixelFormat); ??
  123. ????????????Graphics?g?=?Graphics.FromImage(oThumbNail); ??
  124. ????????????g.CompositingQuality?=?CompositingQuality.HighSpeed; ??
  125. ????????????g.SmoothingMode?=?SmoothingMode.HighSpeed; ??
  126. ????????????g.InterpolationMode?=?InterpolationMode.HighQualityBilinear; ??
  127. ????????????Rectangle?oRectangle?=?new?Rectangle(0,?0,?twidth,?theight); ??
  128. ????????????g.DrawImage(imgOutput,?oRectangle); ??
  129. ????????????try??
  130. ????????????{ ??
  131. ????????????????return?(Bitmap)oThumbNail; ??
  132. ????????????} ??
  133. ????????????catch?(Exception?ex) ??
  134. ????????????{ ??
  135. ????????????????return?null; ??
  136. ????????????} ??
  137. ????????????finally??
  138. ????????????{ ??
  139. ????????????????imgOutput.Dispose(); ??
  140. ????????????????imgOutput?=?null; ??
  141. ????????????????MyBrowser.Dispose(); ??
  142. ????????????????MyBrowser?=?null; ??
  143. ????????????} ??
  144. ????????} ??
  145. ????} ??
  146. ??
  147. }??

轉載于:https://www.cnblogs.com/liufei88866/archive/2010/06/22/1762657.html

總結

以上是生活随笔為你收集整理的C#实现网页截图功能的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。