diff --git a/binding/Binding/SKPixmap.cs b/binding/Binding/SKPixmap.cs index 928bf5fc..8fc3907f 100644 --- a/binding/Binding/SKPixmap.cs +++ b/binding/Binding/SKPixmap.cs @@ -118,7 +118,8 @@ namespace SkiaSharp public bool ReadPixels (SKImageInfo dstInfo, IntPtr dstPixels, int dstRowBytes, int srcX, int srcY) { - return SkiaApi.sk_pixmap_read_pixels (Handle, ref dstInfo, dstPixels, (IntPtr)dstRowBytes, srcX, srcY); + var cinfo = SKImageInfoNative.FromManaged (ref dstInfo); + return SkiaApi.sk_pixmap_read_pixels (Handle, ref cinfo, dstPixels, (IntPtr)dstRowBytes, srcX, srcY); } public bool ReadPixels (SKImageInfo dstInfo, IntPtr dstPixels, int dstRowBytes) diff --git a/binding/Binding/SkiaApi.cs b/binding/Binding/SkiaApi.cs index 5c8b3441..a4747afb 100755 --- a/binding/Binding/SkiaApi.cs +++ b/binding/Binding/SkiaApi.cs @@ -1384,7 +1384,7 @@ namespace SkiaSharp public extern static bool sk_pixmap_encode_image(sk_wstream_t dst, sk_pixmap_t src, SKEncodedImageFormat encoder, int quality); [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] - public extern static bool sk_pixmap_read_pixels(sk_pixmap_t cpixmap, ref SKImageInfo dstInfo, IntPtr dstPixels, IntPtr dstRowBytes, int srcX, int srcY); + public extern static bool sk_pixmap_read_pixels(sk_pixmap_t cpixmap, ref SKImageInfoNative dstInfo, IntPtr dstPixels, IntPtr dstRowBytes, int srcX, int srcY); // Mask [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] diff --git a/tests/Tests/SKPixmapTests.cs b/tests/Tests/SKPixmapTests.cs new file mode 100644 index 00000000..2e35d60c --- /dev/null +++ b/tests/Tests/SKPixmapTests.cs @@ -0,0 +1,46 @@ +using System.Runtime.InteropServices; +using NUnit.Framework; + +namespace SkiaSharp.Tests +{ + public class SKPixmapTest : SKTest + { + [Test] + public void ReadPixelSucceeds() + { + var info = new SKImageInfo(10, 10); + + var ptr1 = Marshal.AllocCoTaskMem(info.BytesSize); + var pix1 = new SKPixmap(info, ptr1); + + var ptr2 = Marshal.AllocCoTaskMem(info.BytesSize); + + var result = pix1.ReadPixels(info, ptr2, info.RowBytes); + + Assert.True(result); + } + + [Test] + public void ReadPixelCopiesData() + { + var info = new SKImageInfo(10, 10); + + using (var bmp1 = new SKBitmap(info)) + using (var pix1 = bmp1.PeekPixels()) + using (var bmp2 = new SKBitmap(info)) + using (var pix2 = bmp2.PeekPixels()) + { + bmp1.Erase(SKColors.Blue); + bmp1.Erase(SKColors.Green); + + Assert.AreNotEqual(Marshal.ReadInt64(pix1.GetPixels()), Marshal.ReadInt64(pix2.GetPixels())); + + var result = pix1.ReadPixels(pix2); + + Assert.True(result); + + Assert.AreEqual(Marshal.ReadInt64(pix1.GetPixels()), Marshal.ReadInt64(pix2.GetPixels())); + } + } + } +}