C#中,窗口快照生成图片保存在本地是如何实现的?跪求例子。。。

2024-11-01 23:33:20
有1个网友回答
网友(1):

            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));//从屏幕截取图像,范围可自己调整
            SaveFileDialog op = new SaveFileDialog();
            op.Filter = "图片文件|*.bmp;*,jpg;*.png";
            if (op.ShowDialog() == DialogResult.OK)//显示保存文件对话框
            {
                image.Save(op.FileName);//保存图片
                MessageBox.Show("图片保存成功!");
            }
            imgGraphics.Dispose();
            image.Dispose();