C# 截取屏幕方法

 this.Visible = false;
            System.Threading.Thread.Sleep(200);
            Bitmap bit = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics g = Graphics.FromImage(bit);
            g.CopyFromScreen(new Point(0, 0), new Point(0, 0), bit.Size);
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "bmp|*.bmp|jpg|*.jpg|gif|*.gif";
            if (saveFileDialog.ShowDialog() != DialogResult.Cancel)
            {
                bit.Save(saveFileDialog.FileName);
            }
            g.Dispose();
            this.Visible = true;

 

截图窗体方法

 Bitmap bit = new Bitmap(this.Width,this.Height);
            Graphics g = Graphics.FromImage(bit);
            g.CopyFromScreen(this.Location, new Point(0, 0), bit.Size);
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "bmp|*.bmp|jpg|*.jpg|gif|*.gif";
            if (saveFileDialog.ShowDialog() != DialogResult.Cancel)
            {
                bit.Save(saveFileDialog.FileName);
            }
            g.Dispose();

 

posted @ 2016-12-01 09:53  指间的徘徊  阅读(1662)  评论(0编辑  收藏  举报