当前位置:主页   - 电脑 - 程序设计 - C#
C#抓屏(截屏)
来源:网络   作者:   更新时间:2012-02-06
收藏此页】    【字号    】    【打印】    【关闭

  先是给大家一个类:

  class ScreenShot
  {
    public static void CaptureImage(Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle, string FilePath)
    {
      using (Bitmap bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height))
      {
        using (Graphics g = Graphics.FromImage(bitmap))
        {
          g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);
        }
        bitmap.Save(FilePath, ImageFormat.Bmp);
      }
    }
  }

   所需添加引用如下:

  using System;

  using System.Drawing;

  using System.Drawing.Imaging;

   调用方法:

    private void button1_Click(object sender, EventArgs e)
    {
      saveFileDialog1.DefaultExt = "bmp";
      saveFileDialog1.Filter = "bmp files (*.bmp)|*.bmp";
      saveFileDialog1.Title = "导出地图为...";
      saveFileDialog1.ShowDialog();
      if (saveFileDialog1.FileName.Length > 0)
      {
        ScreenPath = saveFileDialog1.FileName;
      }
      else
      {
        return;
      }
      this.Refresh_PB_PB_PB_PB_PB_PB_PB();
      //3个参数:获得控件所在屏幕坐标,目标坐标点为(0,0),获得控件大小。
      ScreenShot.CaptureImage(axMapControl1.PointToScreen(Point.Empty), Point.Empty, new Rectangle(axMapControl1.Location, axMapControl1.Size), ScreenPath);    
    }

  转自:http://www.smartgz.com/blog/Article/1110.asp

其它资源
来源声明

版权与免责声明
1、本站所发布的文章仅供技术交流参考,本站不主张将其做为决策的依据,浏览者可自愿选择采信与否,本站不对因采信这些信息所产生的任何问题负责。
2、本站部分文章来源于网络,其版权为原权利人所有。由于来源之故,有的文章未能获得作者姓名,署“未知”或“佚名”。对于这些文章,有知悉作者姓名的请告知本站,以便及时署名。如果作者要求删除,我们将予以删除。除此之外本站不再承担其它责任。
3、本站部分文章来源于本站原创,本站拥有所有权利。
4、如对本站发布的信息有异议,请联系我们,经本站确认后,将在三个工作日内做出修改或删除处理。
请参阅权责声明