0

I want to search in an image for pixels above or below a certain value once that image has been read from a file and converted to a byte array. The Count method for a byte array is quite fast:

int numHighSaturatedPixels = imageArray.Count(n => n == highThreshold)

but the header information from the image format (BMP in my case) is still in there and is included in the count. How can the image be converted to a byte array without the header data getting in there?

Dave R
  • 31
  • 4
  • See [this answer](https://stackoverflow.com/a/3801291) in the question you already looked at. That uses the WPF API. I've added other duplicates that include GDI+ and `LockBits` as well, since it's not clear in your question which API you want to use. – Peter Duniho Mar 06 '21 at 21:15
  • Oops, sorry for the confusion, I'm using WinForms. The CopyPixels method isn't in Bitmap in that case. – Dave R Mar 06 '21 at 21:53
  • That's okay... you can still use the other methods, like `LockBits()`. – Peter Duniho Mar 06 '21 at 22:33
  • Tried the solution suggested by @PeterDuniho and it works perfectly. [This page](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bitmap.lockbits?view=net-5.0) has a good example that I followed. Thanks, Peter! – Dave R Mar 07 '21 at 20:17

0 Answers0