位图图像 - 减少像素数

Bitmap image - Decrease the number of pixels

我正在使用以下代码

Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height); 
Graphics graphics = Graphics.FromImage(bitmap as Image); 
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size); 
bitmap.Save(@"C:\test60.png", ImageFormat.Png);

代码有效。我使用 graphics.CopyFromScreen() 截取屏幕截图并使用 bitmap.Save().

保存位图

图片由 2560x1440 像素组成。基本上我想遍历像素寻找颜色值。

3,686,400 次查询对我来说太多了,我想减少像素数,这意味着图像质量会下降。有没有可能 图像处理要减少多少像素?使一些像素模糊在一起并产生平均值?

我设置为bitmap.SetResolution(800, 600);但不幸的是它没有用。

这应该可以解决问题。

Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(bitmap as Image);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);

Bitmap smallBmp = new Bitmap(bitmap, new Size(800, 600));
smallBmp.Save(@"C:\test60.png", ImageFormat.Png);