private static Func<int, int, int, int> GetPixelMapper(PixelFormat pixelFormat, int heightStride) { switch (pixelFormat) { case PixelFormat.Format32bppArgb: return (h, w, c) => h * heightStride + w * 4 + c; // bytes are B-G-R-A case PixelFormat.Format24bppRgb: default: return (h, w, c) => h * heightStride + w * 3 + c; // bytes are B-G-R } }