コード例 #1
0
        private void OnCropImage(object sender, EventArgs e)
        {
            using var cropPath = new SKPath();
            cropPath.AddPoly(cropPoints.ToArray());

            // add a little padding all round
            var bounds = SKRectI.Ceiling(cropPath.TightBounds);

            bounds.Inflate(4, 4);

            var info = new SKImageInfo(bounds.Width, bounds.Height);

            using var surface = SKSurface.Create(info);
            var canvas = surface.Canvas;

            canvas.Clear(SKColors.Transparent);

            canvas.Translate(-bounds.Left, -bounds.Top);
            canvas.ClipPath(cropPath);

            canvas.DrawImage(pickedImage, 0, 0);

            var image = surface.Snapshot();

            Navigation.PushAsync(new PreviewPage(image));
        }
コード例 #2
0
ファイル: SKBasicTypesTest.cs プロジェクト: ywscr/SkiaSharp
 public void SKRectICeilingWorksAsExpected()
 {
     Assert.Equal(new SKRectI(6, 6, 21, 21), SKRectI.Ceiling(new SKRect(5.5f, 5.5f, 20.5f, 20.5f)));
     Assert.Equal(new SKRectI(5, 5, 21, 21), SKRectI.Ceiling(new SKRect(5.5f, 5.5f, 20.5f, 20.5f), true));
     Assert.Equal(new SKRectI(6, 6, 21, 21), SKRectI.Ceiling(new SKRect(5.4f, 5.6f, 20.4f, 20.6f)));
     Assert.Equal(new SKRectI(5, 5, 21, 21), SKRectI.Ceiling(new SKRect(5.4f, 5.6f, 20.4f, 20.6f), true));
     Assert.Equal(new SKRectI(21, 21, 6, 6), SKRectI.Ceiling(new SKRect(20.4f, 20.6f, 5.4f, 5.6f)));
     Assert.Equal(new SKRectI(21, 21, 5, 5), SKRectI.Ceiling(new SKRect(20.4f, 20.6f, 5.4f, 5.6f), true));
 }
コード例 #3
0
ファイル: WCUtils.cs プロジェクト: vexx32/PSWordCloud
        /// <summary>
        /// Sets the contents of the region to the specified path.
        /// </summary>
        /// <param name="region">The region to set the path into.</param>
        /// <param name="path">The path object.</param>
        /// <param name="usePathBounds">Whether to set the region's new bounds to the bounds of the path itself.</param>
        internal static bool SetPath(this SKRegion region, SKPath path, bool usePathBounds)
        {
            if (usePathBounds && path.GetBounds(out SKRect bounds))
            {
                using SKRegion clip = new SKRegion();

                clip.SetRect(SKRectI.Ceiling(bounds));
                return(region.SetPath(path, clip));
            }
            else
            {
                return(region.SetPath(path));
            }
        }