欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#实现屏幕拷贝的方法

程序员文章站 2022-07-22 19:43:03
本文实例讲述了c#实现屏幕拷贝的方法。分享给大家供大家参考。具体如下: 方法一: using system; using system.collections...

本文实例讲述了c#实现屏幕拷贝的方法。分享给大家供大家参考。具体如下:

方法一:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;
using system.drawing.drawing2d;
namespace windowsapplication2
{
  public partial class form21 : form
  {
    public form21()
    {
      initializecomponent();
    }
    private void button1_click(object sender, eventargs e)
    {
      rectangle screenrect = screen.primaryscreen.workingarea;
      bitmap dumpbitmap = new bitmap(screenrect.width, screenrect.height);
      graphics tg = graphics.fromimage(dumpbitmap);
      tg.copyfromscreen(0, 0, 0, 0, new size(dumpbitmap.width, dumpbitmap.height));
      this.picturebox1.backgroundimage = dumpbitmap;
      this.picturebox1.backgroundimagelayout = imagelayout.stretch;
      dumpbitmap.save(@"c:/image1.bmp");
    }
  }
}

方法二:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;
namespace windowsapplication2
{
  public partial class form22 : form
  {
    public form22()
    {
      initializecomponent();
    }
    private void button1_click(object sender, eventargs e)
    {
      rectangle rect = new rectangle(0, 0, this.size.width, this.size.height);
      bitmap dumpbitmap = new bitmap(this.size.width, this.size.height);
      this.drawtobitmap(dumpbitmap, rect);
      this.picturebox1.backgroundimage = dumpbitmap;
      this.picturebox1.backgroundimagelayout = imagelayout.stretch;
      dumpbitmap.save(@"c:/image2.bmp");
    }
  }
}

希望本文所述对大家的c#程序设计有所帮助。