Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why do I get CS8601 null pointers warning even I do null check before

I have a code piece below which creates an IplImage object from a camera and then creates a bitmap using this iplImage.

var iplImage = Globals.ActiveCamera.Acquisition?.IplImage?.ConvertTo(PixelFormatName.BGR8, ConversionMode.Fast);

if (iplImage == null)
{
    return;
}

frame = new Bitmap(Convert.ToInt16(iplImage?.Width()), Convert.ToInt16(iplImage?.Height()), Convert.ToInt16(iplImage?.PixelFormat().CalculateStorageSizeOfPixels(iplImage.Width())), System.Drawing.Imaging.PixelFormat.Format24bppRgb, iplImage.Data());

Even, I check for null and return if it is. I still get warning CS8601 when using iplImage.Data().

I’m confused what I am missing at this point.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

My suspicion would be that the warning is because

Convert.ToInt16(iplImage?.Width())

has nullable input to Convert.ToInt16. But you know iplImage cannot be null here. So, make it Convert.ToInt16(iplImage.Width()) and Convert.ToInt16(iplImage.Height()) respective.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading