Home > Blockchain >  Bitmap image - Decrease the number of pixels
Bitmap image - Decrease the number of pixels

Time:04-07

I am using the following code

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:\test\2560.png", ImageFormat.Png);

The code works. I take a screenshot of the screen with graphics.CopyFromScreen() and save the bitmap with bitmap.Save().

The image consists of 2560x1440 pixels. Basically I want to step through the pixels looking for a color value.

3,686,400 queries is too much for me and I would like to reduce the number of pixels, which means the image quality will deteriorate. Is there a possibility of Image processing to reduce the number of pixels? So that some pixels blur together and result in an average value?

I set it with bitmap.SetResolution(800, 600); but unfortunately it didn't work.

CodePudding user response:

This should do the trick.

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:\test\2560.png", ImageFormat.Png);
  • Related