开发者

Why is ImageStatistics.Gray null?

开发者 https://www.devze.com 2023-02-23 17:27 出处:网络
I\'m using AForge.net and I want to show in a textbox the value of the standard deviation. The following code is not working:

I'm using AForge.net and I want to show in a textbox the value of the standard deviation. The following code is not working:

AFor开发者_Go百科ge.Imaging.ImageStatistics stat = new AForge.Imaging.ImageStatistics(btm_1);
AForge.Math.Histogram gray = stat.Gray;
this.textB_1.Text = gray.StdDev.ToString();

It fails with the following error:

Object reference not set to an instance of an object.

Both gray and stat.Gray are null.


Did you have a grayscale image?


The official documentation for the Gray property says:

Note:The property is valid only for grayscale images (see IsGrayscale property).

I'm guessing that your image is not a grayscale image, and the Gray property is returning null. It would be preferable that it throw an InvalidOperationException because it could give some insight into the cause of the error, and it would fail fast.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号