Added the C# API for SkBitmapScaler::Resize
This commit is contained in:
Родитель
0e9b000090
Коммит
ec6a87480e
|
@ -635,6 +635,14 @@ namespace SkiaSharp
|
|||
BgrVertical
|
||||
}
|
||||
|
||||
public enum SKBitmapResizeMethod {
|
||||
Box,
|
||||
Triangle,
|
||||
Lanczos3,
|
||||
Hamming,
|
||||
Mitchell
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum SKSurfacePropsFlags {
|
||||
UseDeviceIndependentFonts = 1 << 0,
|
||||
|
|
|
@ -477,6 +477,31 @@ namespace SkiaSharp
|
|||
}
|
||||
}
|
||||
|
||||
public SKBitmap Resize (SKImageInfo info, SKBitmapResizeMethod method)
|
||||
{
|
||||
var dst = new SKBitmap (info);
|
||||
var result = Resize (dst, this, method);
|
||||
if (result) {
|
||||
return dst;
|
||||
} else {
|
||||
dst.Dispose ();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Resize (SKBitmap dst, SKBitmapResizeMethod method)
|
||||
{
|
||||
return Resize (dst, this, method);
|
||||
}
|
||||
|
||||
public static bool Resize (SKBitmap dst, SKBitmap src, SKBitmapResizeMethod method)
|
||||
{
|
||||
using (var srcPix = src.PeekPixels ())
|
||||
using (var dstPix = dst.PeekPixels ()) {
|
||||
return SKPixmap.Resize (dstPix, srcPix, method);// && dst.InstallPixels (dstPix);
|
||||
}
|
||||
}
|
||||
|
||||
// internal proxy
|
||||
#if __IOS__
|
||||
[ObjCRuntime.MonoPInvokeCallback (typeof (SKBitmapReleaseDelegateInternal))]
|
||||
|
|
|
@ -98,5 +98,10 @@ namespace SkiaSharp
|
|||
public SKColorTable ColorTable {
|
||||
get { return GetObject<SKColorTable> (SkiaApi.sk_pixmap_get_colortable (Handle)); }
|
||||
}
|
||||
|
||||
public static bool Resize (SKPixmap dst, SKPixmap src, SKBitmapResizeMethod method)
|
||||
{
|
||||
return SkiaApi.sk_bitmapscaler_resize (dst.Handle, src.Handle, method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1144,6 +1144,9 @@ namespace SkiaSharp
|
|||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public extern static bool sk_bitmap_peek_pixels(sk_bitmap_t cbitmap, sk_pixmap_t cpixmap);
|
||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public extern static bool sk_bitmapscaler_resize(sk_pixmap_t cdst, sk_pixmap_t csrc, SKBitmapResizeMethod method);
|
||||
|
||||
// SkPixmap
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit eeb1435233f45a2cdb053c522fd26fb1e5355a89
|
||||
Subproject commit 4b0bfe18dad276200bdd2ff43fc084da38e76d02
|
|
@ -59,5 +59,29 @@ namespace SkiaSharp.Tests
|
|||
Assert.AreEqual(bitmap.GetPixels(), pixmap.GetPixels());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BitmapResizes()
|
||||
{
|
||||
var srcInfo = new SKImageInfo(200, 200);
|
||||
var dstInfo = new SKImageInfo(100, 100);
|
||||
|
||||
var srcBmp = new SKBitmap(srcInfo);
|
||||
|
||||
using (var canvas = new SKCanvas(srcBmp))
|
||||
using (var paint = new SKPaint { Color = SKColors.Green }) {
|
||||
canvas.Clear(SKColors.Blue);
|
||||
canvas.DrawRect(new SKRect(0, 0, 100, 200), paint);
|
||||
}
|
||||
|
||||
Assert.AreEqual(SKColors.Green, srcBmp.GetPixel(75, 75));
|
||||
Assert.AreEqual(SKColors.Blue, srcBmp.GetPixel(175, 175));
|
||||
|
||||
var dstBmp = srcBmp.Resize(dstInfo, SKBitmapResizeMethod.Mitchell);
|
||||
Assert.IsNotNull(dstBmp);
|
||||
|
||||
Assert.AreEqual(SKColors.Green, dstBmp.GetPixel(25, 25));
|
||||
Assert.AreEqual(SKColors.Blue, dstBmp.GetPixel(75, 75));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче