public void CopyToSucceeds(SKColorType colorType) { var alphaType = colorType.GetAlphaType(); using var bmp = CreateTestBitmap(); using var copy = bmp.Copy(colorType); if (colorType == SKColorType.Unknown) { Assert.Null(copy); } else { Assert.NotNull(copy); Assert.Equal(colorType, copy.ColorType); Assert.Equal(alphaType, copy.AlphaType); var color = copy.GetPixel(10, 10); Assert.NotEqual(SKColors.Empty, color); if (colorType == SKColorType.Gray8) { Assert.Equal(0xFF353535, color); } else if (colorType == SKColorType.Alpha8 || colorType == SKColorType.AlphaF16 || colorType == SKColorType.Alpha16) { Assert.Equal(0xFF000000, color); } else { Assert.Equal(0xFFFF0000, color); } } }
public void CopyWithAlphaToSucceeds(SKColorType colorType) { var alphaType = colorType.GetAlphaType(); using var bmp = CreateTestBitmap(170); using var copy = bmp.Copy(colorType); if (colorType == SKColorType.Unknown) { Assert.Null(copy); } else { Assert.NotNull(copy); Assert.Equal(colorType, copy.ColorType); Assert.Equal(alphaType, copy.AlphaType); var color = copy.GetPixel(10, 10); Assert.NotEqual(SKColors.Empty, color); if (colorType == SKColorType.Gray8) { Assert.Equal((SKColor)0xFF232323, color); } else if (alphaType == SKAlphaType.Opaque) { Assert.True(color.Red > color.Green); Assert.True(color.Red > color.Blue); Assert.Equal(255, color.Alpha); } else if (colorType == SKColorType.Alpha8 || colorType == SKColorType.Alpha16) { Assert.Equal((SKColor)0xAA000000, color); } else if (colorType == SKColorType.AlphaF16) { // rounding Assert.Equal((SKColor)0xA9000000, color); } else { Assert.Equal((SKColor)0xAAFF0000, color); } } }