gpt4 book ai didi

c# - GetPixel(ScreenWidth, ScreenHeight) 抛出异常

转载 作者:行者123 更新时间:2023-11-30 20:20:39 25 4
gpt4 key购买 nike

我有一台 1080P 显示器。做

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

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

最佳答案

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

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

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

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

关于c# - GetPixel(ScreenWidth, ScreenHeight) 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35877075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com