예제 #1
0
        //Render:When your image has changed, call it
        public void Render(ICanvasResourceCreator creator, float scaleX, float scaleY, ICanvasImage image)
        {
            //Scale :zoom up
            ScaleEffect effect = new ScaleEffect
            {
                Source            = image,
                Scale             = new Vector2(1 / scaleX, 1 / scaleY),
                InterpolationMode = CanvasImageInterpolation.NearestNeighbor,
            };
            //Crop:So that it does not exceed the canvas boundary
            Rect       rect    = effect.GetBounds(creator);
            CropEffect effect2 = new CropEffect
            {
                Source          = effect,
                SourceRectangle = new Rect(2, 2, rect.Width - 4, rect.Height - 4),
            };


            //DottedLine
            this.OutPut = new LuminanceToAlphaEffect //Alpha
            {
                Source = new EdgeDetectionEffect     //Edge
                {
                    Amount = 1,
                    Source = effect2
                },
            };
        }
예제 #2
0
        public void PaintSet(ICanvasResourceCreator rc, CanvasBitmap cb, float R, Color co)
        {
            //Paint:绘画
            Paint = new CanvasCommandList(rc);

            using (CanvasDrawingSession ds = Paint.CreateDrawingSession())
            {
                ds.FillEllipse(0, 0, R, R, PaintBrush(rc, R, PaintHard, PaintOpacity, co));

                ICanvasImage ci = new ScaleEffect
                {
                    Source = cb,
                    Scale  = new Vector2(2 * R / cb.SizeInPixels.Width)
                };
                ds.DrawImage(ci, -R, -R, ci.GetBounds(rc), 1, CanvasImageInterpolation.HighQualityCubic, CanvasComposite.DestinationIn);
            }



            //Show:展示
            var radius = (float)Math.Sqrt(R);

            PaintShow = new CanvasCommandList(rc);

            using (CanvasDrawingSession ds = PaintShow.CreateDrawingSession())
            {
                ds.FillEllipse(0, 0, radius, radius, PaintBrush(rc, radius, PaintHard, PaintOpacity, Colors.White));
                ICanvasImage ci = new ScaleEffect
                {
                    Source = cb,
                    Scale  = new Vector2(2 * radius / cb.SizeInPixels.Width)
                };
                ds.DrawImage(ci, -radius, -radius, ci.GetBounds(rc), 1, CanvasImageInterpolation.HighQualityCubic, CanvasComposite.DestinationIn);
            }
        }
예제 #3
0
        //方法:设置(写到创建资源事件里)
        public void Set(ICanvasResourceCreator rc, float sx, float sy, ICanvasImage ci)
        {
            //放大
            ScaleEffect se = new ScaleEffect
            {
                Source            = ci,
                Scale             = new Vector2(1 / sx, 1 / sy),
                InterpolationMode = CanvasImageInterpolation.NearestNeighbor,
            };

            //剪裁四周的边线
            var        rect = se.GetBounds(rc);
            CropEffect sce  = new CropEffect
            {
                Source          = se,
                SourceRectangle = new Rect(2, 2, rect.Width - 4, rect.Height - 4),
            };

            //恢复正常大小
            CanvasCommandList ccl = new CanvasCommandList(rc);

            using (var ds = ccl.CreateDrawingSession())
            {
                ds.Clear(Colors.Transparent);
                ds.DrawImage(sce);
            }

            //变成线框
            Image = new LuminanceToAlphaEffect   //亮度转不透明度
            {
                Source = new EdgeDetectionEffect //边缘检测
                {
                    Amount = 1,
                    Source = ccl
                },
            };
        }