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

      歡迎訪問 生活随笔!

      生活随笔

      當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

      编程问答

      截取控件界面

      發布時間:2023/12/19 编程问答 32 豆豆
      生活随笔 收集整理的這篇文章主要介紹了 截取控件界面 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

      介紹:
      ?做項目中,遇到需要截取界面圖形的內容,查找了所有的Graphics函數,
      ?都沒有此功能。只能用GDI32中的BitBlt來解決。
      應用需要調用的函數
      ? class GDI32
      ?{
      ??[DllImport("GDI32.dll")]
      ??public static extern bool BitBlt(int hdcDest,int nXDest,int nYDest,
      ???int nWidth,int nHeight,int hdcSrc,
      ???int nXSrc,int nYSrc,int dwRop);
      ??[DllImport("GDI32.dll")]
      ??public static extern int CreateCompatibleBitmap(int hdc,int nWidth,
      ???int nHeight);
      ??[DllImport("GDI32.dll")]
      ??public static extern int CreateCompatibleDC(int hdc);
      ??[DllImport("GDI32.dll")]
      ??public static extern bool DeleteDC(int hdc);
      ??[DllImport("GDI32.dll")]
      ??public static extern bool DeleteObject(int hObject);
      ??[DllImport("GDI32.dll")]
      ??public static extern int GetDeviceCaps(int hdc,int nIndex);
      ??[DllImport("GDI32.dll")]
      ??public static extern int SelectObject(int hdc,int hgdiobj);

      ??
      ?
      ??public static void Cleanup(int hBitmap,int hdcSrc,int hdcDest)
      ??{
      ???// Release the device context resources back to the system
      ???User32.ReleaseDC(User32.GetDesktopWindow(),hdcSrc);
      ???GDI32.DeleteDC(hdcDest);
      ???GDI32.DeleteObject(hBitmap);?
      ??}
      ?
      ??public static void SaveImageAs(int hBitmap,string fileName,ImageFormat imageFormat)
      ??{
      ???// Create a bitmap from the Windows handle
      ???Bitmap image =
      ????new Bitmap(Image.FromHbitmap(new IntPtr(hBitmap)),
      ????Image.FromHbitmap(new IntPtr(hBitmap)).Width,
      ????Image.FromHbitmap(new IntPtr(hBitmap)).Height);
      ???image.Save(fileName,imageFormat);
      ??}????

      ?
      ?}
      ?class User32
      ?{
      ??[DllImport("User32.dll")]
      ??public static extern int GetDesktopWindow();
      ??[DllImport("User32.dll")]
      ??public static extern int GetWindowDC(int hWnd);
      ??[DllImport("User32.dll")]
      ??public static extern int ReleaseDC(int hWnd,int hDC);
      ?}
      具體實現的方式
      ???? 和C++中的代碼類似
      ??????? int hdcSrc = User32.GetWindowDC((int)this.control.Handle), // 獲得控件的Handle
      ???? hdcDest = GDI32.CreateCompatibleDC(hdcSrc), // 創建兼容DC
      ???? hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc,
      ???this.control.Width,this.control.Height);//創建
      ???? GDI32.SelectObject(hdcDest,hBitmap); // 選擇
      ???? GDI32.BitBlt(hdcDest,0,0,this.control.Width,
      ???this.control.Height,
      ???hdcSrc,0,0,0x00CC0020);//繪制圖形
      ???? Bitmap image = new Bitmap(Image.FromHbitmap(new IntPtr(hBitmap)),
      ???Image.FromHbitmap(new IntPtr(hBitmap)).Width,
      ???Image.FromHbitmap(new IntPtr(hBitmap)).Height);//轉換為.net的Image類型
      ??? GDI32.Cleanup(hBitmap,hdcSrc,hdcDest);//清除句柄

      轉載于:https://www.cnblogs.com/wanghualiang/archive/2006/01/20/320709.html

      總結

      以上是生活随笔為你收集整理的截取控件界面的全部內容,希望文章能夠幫你解決所遇到的問題。

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