Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetPixel(ScreenWidth, ScreenHeight) throws exception

I have a 1080P monitor. Doing

int j Screen.PrimaryScreen.Bounds.Width;
int k = Screen.PrimaryScreen.Bounds.Height;
_Bitmap.GetPixel(j, k).GetBrightness();

(_Bitmap size is equal to my screen bounds), it throws an exception saying "Parameter must be positive and < height".

like image 872
madkaratemans Avatar asked Dec 13 '25 15:12

madkaratemans


1 Answers

Width and Height start counting at 1, the indexes used in GetPixel() start at 0. So when trying to acces the Pixel at (Width,Height) nothing is found

To correct the error change the code to (for example):

int width = Screen.PrimaryScreen.Bounds.Width;
int height = Screen.PrimaryScreen.Bounds.Height;

_Bitmap.GetPixel(width-1,height-1).GetBrightness();
like image 170
Breeze Avatar answered Dec 16 '25 04:12

Breeze