From 42a1a4abe843a4ad4485be1b0caa0dbea34c322f Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Sat, 13 May 2017 02:54:24 +0200 Subject: [PATCH] For backwards compatibility, we are not going to use a colorspace when decoding with SKBitmap.Decode(...) --- binding/Binding/SKBitmap.cs | 2 ++ tests/Tests/SKBitmapTest.cs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index 186a9190..11becc54 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -414,6 +414,8 @@ namespace SkiaSharp if (info.AlphaType == SKAlphaType.Unpremul) { info.AlphaType = SKAlphaType.Premul; } + // for backwards compatibility, remove the colorspace + info.ColorSpace = null; return Decode (codec, info); } diff --git a/tests/Tests/SKBitmapTest.cs b/tests/Tests/SKBitmapTest.cs index 1c784ca5..edd5c38e 100644 --- a/tests/Tests/SKBitmapTest.cs +++ b/tests/Tests/SKBitmapTest.cs @@ -97,6 +97,27 @@ namespace SkiaSharp.Tests Assert.AreEqual(new SKPointI(-7, -7), offset); } + [Test] + public void TestBitmapDecodeDrawsCorrectly() + { + var path = Path.Combine(PathToImages, "color-wheel.png"); + + using (var bitmap = SKBitmap.Decode(path)) + using (var surface = SKSurface.Create(new SKImageInfo(200, 200))) { + var canvas = surface.Canvas; + canvas.Clear(SKColors.White); + canvas.DrawBitmap(bitmap, 0, 0); + + using (var img = surface.Snapshot()) + using (var bmp = SKBitmap.FromImage(img)) { + Assert.AreEqual(new SKColor(2, 255, 42), bmp.GetPixel(20, 20)); + Assert.AreEqual(new SKColor(1, 83, 255), bmp.GetPixel(108, 20)); + Assert.AreEqual(new SKColor(255, 166, 1), bmp.GetPixel(20, 108)); + Assert.AreEqual(new SKColor(255, 1, 214), bmp.GetPixel(108, 108)); + } + } + } + [Test] public void BitmapAndPixmapAreValid() {