예제 #1
0
        public void TrimPathEffectWorks()
        {
            using (var bitmap = new SKBitmap(new SKImageInfo(100, 100)))
                using (var canvas = new SKCanvas(bitmap))
                    using (var path = new SKPath())
                    {
                        path.MoveTo(0, 50);
                        path.LineTo(new SKPoint(100, 50));
                        canvas.Clear(SKColors.White);

                        // draw the base path
                        using (var paint = new SKPaint())
                        {
                            paint.Style       = SKPaintStyle.Stroke;
                            paint.StrokeWidth = 20;
                            paint.Color       = SKColors.Black;

                            canvas.DrawPath(path, paint);
                        }

                        // should be black
                        Assert.Equal(SKColors.Black, bitmap.GetPixel(10, 50));
                        Assert.Equal(SKColors.Black, bitmap.GetPixel(50, 50));
                        Assert.Equal(SKColors.Black, bitmap.GetPixel(90, 50));

                        // draw the path with an effect
                        using (var paint = new SKPaint())
                        {
                            paint.Style       = SKPaintStyle.Stroke;
                            paint.StrokeWidth = 20;
                            paint.Color       = SKColors.Red;

                            // attach the effect
                            paint.PathEffect = SKPathEffect.CreateTrim(0.3f, 0.7f);

                            canvas.DrawPath(path, paint);
                        }

                        // should be red
                        Assert.Equal(SKColors.Black, bitmap.GetPixel(10, 50));
                        Assert.Equal(SKColors.Red, bitmap.GetPixel(50, 50));
                        Assert.Equal(SKColors.Black, bitmap.GetPixel(90, 50));
                    }
        }