C# GetPixel(屏幕宽度、屏幕高度)引发异常
我有一台1080P显示器。做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等于我的屏幕边界),它抛出一个异常,表示“参数必须为正且
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();