public byte GetIntensity(int x, int y) { if (!IsLocked) { LockBits(); } // Get start index of the specified pixel int i = (y * Stride) + x * BytesPerPixel; if (i > _pixelData.Length - BytesPerPixel) { throw new IndexOutOfRangeException(); } if (BitsPerPixel == 32) { // Note: Ignoring Alpha (which is index i) return(ColorExtensions.GetIntensity(_pixelData[i + 3], _pixelData[i + 2], _pixelData[i + 1])); } if (BitsPerPixel == 24) { return(ColorExtensions.GetIntensity(_pixelData[i + 2], _pixelData[i + 1], _pixelData[i])); } if (BitsPerPixel == 8) { return(_pixelData[i]); } throw new NotImplementedException(); }