VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > c#编程 >
  • C#教程之c#不使用系统api实现可以指定区域屏幕截

复制代码 代码如下:

//截取全屏图象
        private void btnFullScreen_Click(object sender, EventArgs e)
        {
            //创建图象,保存将来截取的图象
            Bitmap image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics imgGraphics = Graphics.FromImage(image);
            //设置截屏区域
            imgGraphics.CopyFromScreen(0, 0, 0, 0, new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
            //保存
            SaveImage(image);
        }

 

//保存图象文件
        private void SaveImage(Image image)
        {
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string fileName = saveFileDialog.FileName;
                string extension = Path.GetExtension(fileName);
                if (extension == ".jpg")
                {
                    image.Save(fileName, ImageFormat.Jpeg);
                }
                else
                {
                    image.Save(fileName, ImageFormat.Bmp);
                }
            }
        }

 


相关教程