GetPixel(ScreenWidth,ScreenHeight)抛出异常

时间:2016-03-08 20:09:13

标签: c# visual-studio-2013

我有一台1080P显示器。做

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

(_位图大小等于我的屏幕边界),它会抛出一个异常,说"参数必须为正且<高度"

1 个答案:

答案 0 :(得分:6)

宽度和高度从1开始计数,GetPixel()中使用的索引从0开始。因此,当尝试在(宽度,高度)处访问Pixel时,找不到任何内容

要更正错误,请将代码更改为(例如):

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

_Bitmap.GetPixel(width-1,height-1).GetBrightness();