Corrected the marshalling. Fixes #333
This commit is contained in:
Родитель
de0945ba32
Коммит
f900f3215c
|
@ -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)
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче