Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GetPixel(屏幕宽度、屏幕高度)引发异常_C#_Visual Studio 2013 - Fatal编程技术网

C# GetPixel(屏幕宽度、屏幕高度)引发异常

C# GetPixel(屏幕宽度、屏幕高度)引发异常,c#,visual-studio-2013,C#,Visual Studio 2013,我有一台1080P显示器。做 int j Screen.PrimaryScreen.Bounds.Width; int k = Screen.PrimaryScreen.Bounds.Height; _Bitmap.GetPixel(j, k).GetBrightness(); (_bitmapsize等于我的屏幕边界),它抛出一个异常,表示“参数必须为正且

我有一台1080P显示器。做

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

(_bitmapsize等于我的屏幕边界),它抛出一个异常,表示“参数必须为正且<高度”。

宽度和高度从1开始计数,GetPixel()中使用的索引从0开始。因此,当尝试访问(宽度、高度)的像素时,什么也找不到

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


位图是否与屏幕大小相同?你想在这里做什么?@BJ迈尔斯抱歉说得不够清楚。位图是我的屏幕截图。是的,这是我屏幕的大小。
int width = Screen.PrimaryScreen.Bounds.Width;
int height = Screen.PrimaryScreen.Bounds.Height;

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