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.
精彩评论