protected NativeBitmapDataBase(Bitmap bitmap, PixelFormat pixelFormat, ImageLockMode lockMode, Color32 backColor, byte alphaThreshold, Palette?palette) { // It must be the same as bitmap format except if LockBits is not supported with the original pixel format (occurs on Linux). Debug.Assert(bitmap.PixelFormat == pixelFormat || !OSUtils.IsWindows, "Unmatching pixel format"); // If palette is passed it must match with actual palette Debug.Assert(palette == null || palette.Equals(bitmap.Palette.Entries), "Unmatching palette"); this.bitmap = bitmap; BackColor = pixelFormat.HasMultiLevelAlpha() ? default : backColor.ToOpaque(); AlphaThreshold = alphaThreshold; bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), lockMode, pixelFormat); RowSize = Math.Abs(bitmapData.Stride); if (pixelFormat.IsIndexed()) { Palette = palette ?? new Palette(bitmap.Palette.Entries, backColor.ToColor(), alphaThreshold); } }