环境:VS2005 C# WinForm截屏代码: private void button2_Click(object sender, EventArgs e)
{
Bitmap screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(screenBitmap);
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
g.Dispose();
this.pictureBox1.Image = screenBitmap;
}
除了这种方法,网上所流传的API法我也试了,它们都存在一个问题:图像黑色部分会出现白色絮状失真,如下图所示:
求解决办法
{
Bitmap screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(screenBitmap);
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
g.Dispose();
this.pictureBox1.Image = screenBitmap;
}
除了这种方法,网上所流传的API法我也试了,它们都存在一个问题:图像黑色部分会出现白色絮状失真,如下图所示:
求解决办法
http://newspic.cn.yahoo.com/newspic/bbs/2176/
1,截图并没有错,因为你如果 save 至文件,可以双击打开文件,那文件并没有颜色的错误.
2,问题出在PictureBox
你应该运行一句 pictureBox1.BackColor = Color.Black; 显示就没问题了.
Bitmap screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(screenBitmap);
g.CopyFromScreen(20, 80, 0, 0, Screen.PrimaryScreen.Bounds.Size);
g.Dispose();
screenBitmap.Save("d:\\a.jpg"); // 保存的文件,打开显示OK
this.pictureBox1.Image = screenBitmap;
this.pictureBox1.BackColor = Color.Black; // 这里如果设置为Color.Red,就会看到那些失真的部分成了红色.