国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#截屏

2024-07-21 02:25:53
字體:
來源:轉載
供稿:網友

using system;
using system.runtime.interopservices;
using system.drawing;
using system.drawing.imaging;

namespace csharpchat
{
 /// <summary>
 /// screencameraclass 的摘要說明。
 /// </summary>
 public class screencameraclass
 {
  public screencameraclass()
  {
   //
   // todo: 在此處添加構造函數邏輯
   //
  }
  /**//// <summary>
  /// creates an image object containing a screen shot of the entire desktop?
  /// </summary>
  /// <returns></returns>
  public image capturescreen()
  {
   return capturewindow( user32.getdesktopwindow() );
  }
 
  /**//// <summary>
  /// creates an image object containing a screen shot of a specific window?
  /// </summary>
  /// <param name="handle">the handle to the window. (in windows forms, this is obtained by the handle property)</param>
  /// <returns></returns>
  public image capturewindow(intptr handle)
  {
   // get te hdc of the target window
   intptr hdcsrc = user32.getwindowdc(handle);
   // get the size
   user32.rect windowrect = new user32.rect();
   user32.getwindowrect(handle,ref windowrect);
   int width = windowrect.right - windowrect.left;
   int height = windowrect.bottom - windowrect.top;
   // create a device context we can copy to
   intptr hdcdest = gdi32.createcompatibledc(hdcsrc);
   // create a bitmap we can copy it to,
   // using getdevicecaps to get the width/height
   intptr hbitmap = gdi32.createcompatiblebitmap(hdcsrc,width,height);
   // select the bitmap object
   intptr hold = gdi32.selectobject(hdcdest,hbitmap);
   // bitblt over
   gdi32.bitblt(hdcdest,0,0,width,height,hdcsrc,0,0,gdi32.srccopy);
   // restore selection
   gdi32.selectobject(hdcdest,hold);
   // clean up
   gdi32.deletedc(hdcdest);
   user32.releasedc(handle,hdcsrc);

   // get a .net image object for it
   image img = image.fromhbitmap(hbitmap);
   // free up the bitmap object
   gdi32.deleteobject(hbitmap);

   return img;
  }

  /**//// <summary>
  /// captures a screen shot of a specific window, and saves it to a file?
  /// </summary>
  /// <param name="handle"></param>
  /// <param name="filename"></param>
  /// <param name="format"></param>
  public void capturewindowtofile(intptr handle, string filename, imageformat format)
  {
   image img = capturewindow(handle);
   img.save(filename,format);
  }

  /**//// <summary>
  /// captures a screen shot of the entire desktop, and saves it to a file?
  /// </summary>
  /// <param name="filename"></param>
  /// <param name="format"></param>
  public void capturescreentofile(string filename, imageformat format)
  {
   image img = capturescreen();
   img.save(filename,format);
  }
     
  /**//// <summary>
  /// helper class containing gdi32 api functions
  /// </summary>
  private class gdi32
  {
           
   public const int srccopy = 0x00cc0020; // bitblt dwrop parameter

   [dllimport("gdi32.dll")]
   public static extern bool bitblt(intptr hobject,int nxdest,int nydest,
    int nwidth,int nheight,intptr hobjectsource,
    int nxsrc,int nysrc,int dwrop);
   [dllimport("gdi32.dll")]
   public static extern intptr createcompatiblebitmap(intptr hdc,int nwidth,
    int nheight);
   [dllimport("gdi32.dll")]
   public static extern intptr createcompatibledc(intptr hdc);
   [dllimport("gdi32.dll")]
   public static extern bool deletedc(intptr hdc);
   [dllimport("gdi32.dll")]
   public static extern bool deleteobject(intptr hobject);
   [dllimport("gdi32.dll")]
   public static extern intptr selectobject(intptr hdc,intptr hobject);
  }
 
  /**//// <summary>
  /// helper class containing user32 api functions
  /// </summary>
  private class user32
  {
   [structlayout(layoutkind.sequential)]
    public struct rect
   {
    public int left;
    public int top;
    public int right;
    public int bottom;
   }

   [dllimport("user32.dll")]
   public static extern intptr getdesktopwindow();
   [dllimport("user32.dll")]
   public static extern intptr getwindowdc(intptr hwnd);
   [dllimport("user32.dll")]
   public static extern intptr releasedc(intptr hwnd,intptr hdc);
   [dllimport("user32.dll")]
   public static extern intptr getwindowrect(intptr hwnd,ref rect rect);

  }
 }
}
 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 普兰店市| 玉树县| 康乐县| 历史| 天津市| 清原| 铜陵市| 介休市| 沿河| 五寨县| 景洪市| 怀化市| 武定县| 康马县| 平安县| 乌拉特前旗| 广河县| 仪陇县| 博白县| 肇庆市| 梁山县| 揭西县| 古田县| 阿拉尔市| 布拖县| 安乡县| 沽源县| 广河县| 阿城市| 镇坪县| 苏尼特左旗| 靖江市| 黄平县| 永平县| 巴青县| 郧西县| 广东省| 文登市| 融水| 施甸县| 贡觉县|