public static ICanvasImage RenderTransform(Layer l, ICanvasImage ci)
        {
            if (l.Visual == true && l.Opacity != 0) //图层可视且透明度大于零
            {
                if (l.Opacity == 100)               //无透明度渲染
                {
                    //图层无混合模式
                    if (l.BlendIndex == 0)
                    {
                        ci = new CompositeEffect
                        {
                            Sources = { ci, GetTransform(l.CanvasRenderTarget, l.Vect) }
                        }
                    }
                    ; //结合接口
                    //图层有混合模式
                    else
                    {
                        ci = new BlendEffect()
                        {
                            Background = GetTransform(l.CanvasRenderTarget, l.Vect), Foreground = ci, Mode = l.BlendMode,
                        }
                    };                   //混合接口
                }
                else if (l.Opacity == 0) //透明度渲染
                {
                    return(ci);
                }
                else// if (l.Opacity < 100)//有透明度渲染
                {
                    ICanvasImage oci = new OpacityEffect {
                        Source = GetTransform(l.CanvasRenderTarget, l.Vect), Opacity = (float)(l.Opacity / 100)
                    };                                                                                                                               //透明度接口

                    //图层无混合模式
                    if (l.BlendIndex == 0)
                    {
                        ci = new CompositeEffect {
                            Sources = { ci, oci }
                        }
                    }
                    ;                                                                         //结合接口
                                                                                              //图层有混合模式
                    else
                    {
                        ci = new BlendEffect()
                        {
                            Background = oci, Foreground = ci, Mode = l.BlendMode,
                        }
                    };                                                                                     //混合接口
                }
            }
            return(ci);
        }
Exemple #2
0
        public static CompositionBrush BuildMicaEffectBrush(Compositor compositor, Color tintColor, float tintOpacity, float luminosityOpacity)
        {
            // Tint Color.

            var tintColorEffect = new ColorSourceEffect();

            tintColorEffect.Name  = "TintColor";
            tintColorEffect.Color = tintColor;

            // OpacityEffect applied to Tint.
            var tintOpacityEffect = new OpacityEffect();

            tintOpacityEffect.Name    = "TintOpacity";
            tintOpacityEffect.Opacity = tintOpacity;
            tintOpacityEffect.Source  = tintColorEffect;

            // Apply Luminosity:

            // Luminosity Color.
            var luminosityColorEffect = new ColorSourceEffect();

            luminosityColorEffect.Color = tintColor;

            // OpacityEffect applied to Luminosity.
            var luminosityOpacityEffect = new OpacityEffect();

            luminosityOpacityEffect.Name    = "LuminosityOpacity";
            luminosityOpacityEffect.Opacity = luminosityOpacity;
            luminosityOpacityEffect.Source  = luminosityColorEffect;

            // Luminosity Blend.
            var luminosityBlendEffect = new BlendEffect();

            luminosityBlendEffect.Mode       = BlendEffectMode.Color;
            luminosityBlendEffect.Background = new CompositionEffectSourceParameter("BlurredWallpaperBackdrop");
            luminosityBlendEffect.Foreground = luminosityOpacityEffect;

            // Apply Tint:

            // Color Blend.
            var colorBlendEffect = new BlendEffect();

            colorBlendEffect.Mode       = BlendEffectMode.Luminosity;
            colorBlendEffect.Background = luminosityBlendEffect;
            colorBlendEffect.Foreground = tintOpacityEffect;

            CompositionEffectBrush micaEffectBrush = compositor.CreateEffectFactory(colorBlendEffect).CreateBrush();
            var blurredWallpaperBackdropBrush      = (ICompositorWithBlurredWallpaperBackdropBrush)((object)compositor);

            micaEffectBrush.SetSourceParameter("BlurredWallpaperBackdrop", blurredWallpaperBackdropBrush.TryCreateBlurredWallpaperBackdropBrush());

            return(micaEffectBrush);
        }
        private void Create()
        {
            if (_effectFactory == null)
            {
                var color = new ColorSourceEffect
                {
                    Name  = "Colour",
                    Color = this.TintColor
                };

                var opacity = new OpacityEffect
                {
                    Name    = "Opacity",
                    Opacity = 0f,
                    Source  = color
                };

                var blurEffect = new GaussianBlurEffect
                {
                    Name            = "Blur",
                    BlurAmount      = 0,
                    Optimization    = EffectOptimization.Speed,
                    BorderMode      = EffectBorderMode.Hard,
                    BufferPrecision = Microsoft.Graphics.Canvas.CanvasBufferPrecision.Precision16Float,
                    Source          = new CompositionEffectSourceParameter("Source")
                };

                var blend = new BlendEffect
                {
                    Background = blurEffect,
                    Foreground = opacity,
                    Mode       = BlendEffectMode.SoftLight,
                };

                _effectFactory = _compositor.CreateEffectFactory(
                    blend, new string[] { "Blur.BlurAmount", "Colour.Color", "Opacity.Opacity" });
            }

            var brush = _effectFactory.CreateBrush();

            brush.SetSourceParameter("Source", _compositor.CreateHostBackdropBrush());
            this.CompositionBrush = brush;
            UpdateBlur();
            UpdateColor();
        }
Exemple #4
0
        async Task CreateResourcesAsync(CanvasAnimatedControl sender)
        {
            for (int i = 0; i < shipImages.Length; i++)
            {
                string fileName;
                if (Globals.player.fleet[i].Vertical)
                {
                    fileName = "images/Ships/ship" + (i + 2) + Globals.player.fleet[i].ShipName + ".png";
                }
                else
                {
                    fileName = "images/Ships/ship" + (i + 2) + Globals.player.fleet[i].ShipName + "Hor.png";
                }
                var originalImage = await CanvasBitmap.LoadAsync(sender, fileName);

                shipImages[i]  = Globals.ScaleImage(originalImage);
                shipShadows[i] = GetShipShadow(i);
                var transShip = new OpacityEffect
                {
                    Source  = shipImages[i],
                    Opacity = (float)0.8
                };
                transparentShips[i] = transShip;
                var transShadow = new OpacityEffect
                {
                    Source  = shipShadows[i],
                    Opacity = (float)0.8
                };
                transparentShadows[i] = transShadow;
                if (Globals.player.fleet[i].ShipName.Equals("Submarine"))
                {
                    if (Globals.player.fleet[i].Vertical)
                    {
                        originalImage = await CanvasBitmap.LoadAsync(sender, "images/Ships/ship3SubmarineHor.png");
                    }
                    else
                    {
                        originalImage = await CanvasBitmap.LoadAsync(sender, "images/Ships/ship3Submarine.png");
                    }
                    alternateSubmarine = Globals.ScaleImage(originalImage);
                }
            }
        }
        /// <summary>
        /// Gets a specific actual rended-layer (with icon render).
        /// </summary>
        /// <param name="resourceCreator"> The resource-creator. </param>
        /// <param name="children"> The children layerage. </param>
        /// <returns> The rendered layer. </returns>
        public ICanvasImage GetActualRender(ICanvasResourceCreator resourceCreator, IList <Layerage> children)
        {
            if (this.Render2 == null || this.IsRefactoringRender)
            {
                this.IsRefactoringRender = false;

                {
                    //Layer
                    ICanvasImage currentImage = this.GetRender(resourceCreator, children);

                    //Effect
                    currentImage = Effect.Render(this.Effect, currentImage);

                    //Adjustment
                    currentImage = Filter.Render(this.Filter, currentImage);

                    //Opacity
                    if (this.Opacity < 1.0)
                    {
                        currentImage = new OpacityEffect
                        {
                            Opacity = this.Opacity,
                            Source  = currentImage
                        };
                    }

                    this.Render2 = currentImage;
                }


                if (this.IsRefactoringIconRender)
                {
                    this.IsRefactoringIconRender = false;

                    this.Control.IconRender = this.Render2?.ToIconRenderImage(resourceCreator, LayerageCollection.ControlsHeight);
                }
            }
            return(this.Render2);
        }
Exemple #6
0
        protected override void OnConnected()
        {
            if (CompositionBrush != null)
            {
                return;
            }

            var backdropBlurEffect = new GaussianBlurEffect
            {
                Name       = "Blur",
                BlurAmount = (float)BlurAmount,
                Source     = new CompositionEffectSourceParameter("backdrop")
            };
            var backgroundColorSourceEffect = new ColorSourceEffect
            {
                Name  = "Tint",
                Color = BackgroundColor
            };
            var backgroundColorOpacityEffect = new OpacityEffect
            {
                Name    = "Opacity",
                Opacity = (float)BackgroundColorOpacity,
                Source  = backgroundColorSourceEffect
            };
            var blendEffect = new BlendEffect
            {
                Background = backdropBlurEffect,
                Foreground = backgroundColorOpacityEffect,
                Mode       = BlendEffectMode.Multiply,
            };

            var effectFactory = Window.Current.Compositor.CreateEffectFactory(blendEffect, new[] { "Blur.BlurAmount", "Tint.Color", "Opacity.Opacity" });
            var effectBrush   = effectFactory.CreateBrush();

            effectBrush.SetSourceParameter("backdrop", Window.Current.Compositor.CreateBackdropBrush());

            CompositionBrush = effectBrush;
        }
        private ICanvasImage CreateOpacity()
        {
            if (!OpacityEffect.IsSupported)
            {
                return CreateNotSupportedMessage(requiresWin10_14393);
            }

            textLabel = requiresWin10_14393;

            var opacityEffect = new OpacityEffect
            {
                Source = bitmapTiger
            };

            // Composite the fading tiger on top of a background checker pattern.
            var compositeEffect = new CompositeEffect
            {
                Sources = { CreateCheckeredBackground(), opacityEffect }
            };

            // Animation changes the opacity.
            animationFunction = elapsedTime =>
            {
                opacityEffect.Opacity = 0.5f + (float)Math.Sin(elapsedTime * 2) / 2;
            };

            return compositeEffect;
        }
Exemple #8
0
 private void FinishButton_Click(object sender, RoutedEventArgs e)
 {
     CleanUp();
     for (int i = 0; i < Globals.player.fleet.Length; i++)
     {
         if (Globals.player.fleet[i].ShipName.Contains("temp"))
         {
             if (Globals.player.fleet[i].Length == 2)
             {
                 Globals.player.fleet[i].ShipName = "Scrambler";
                 shipImages[0]  = verticalShips[0];
                 shipShadows[0] = GetShipShadow(0);
             }
             else if (Globals.player.fleet[i].Length == 3)
             {
                 Globals.player.fleet[i].ShipName = "Submarine";
                 shipImages[1]  = verticalShips[2];
                 shipShadows[1] = GetShipShadow(1);
             }
             else if (Globals.player.fleet[i].Length == 4)
             {
                 Globals.player.fleet[i].ShipName = "Cruiser";
                 shipImages[2]  = verticalShips[4];
                 shipShadows[2] = GetShipShadow(2);
             }
             else if (Globals.player.fleet[i].Length == 5)
             {
                 Globals.player.fleet[i].ShipName = "Executioner";
                 shipImages[3]  = verticalShips[6];
                 shipShadows[3] = GetShipShadow(3);
             }
         }
         var transparent = new OpacityEffect
         {
             Source  = shipImages[i],
             Opacity = (float)0.7
         };
         shipImages[i] = transparent;
         var transparentShadow = new OpacityEffect
         {
             Source  = shipShadows[i],
             Opacity = (float)0.7
         };
         shipShadows[i] = transparentShadow;
     }
     foreach (Button b in shipSelectButtons)
     {
         b.IsEnabled = false;
     }
     hoveredShip                          = null;
     clickedShip                          = null;
     moveError                            = null;
     finishButton.IsEnabled               = false;
     shipDescriptionTitle.Text            = "";
     shipDescriptionDetails.Foreground    = new SolidColorBrush(Windows.UI.Colors.White);
     shipDescriptionDetails.TextAlignment = TextAlignment.Center;
     shipDescriptionDetails.FontFamily    = new FontFamily("Stencil");
     shipDescriptionDetails.FontSize      = 28;
     shipDescriptionDetails.Text          = "\nWaiting for other player...";
     timerText.Text                       = "";
     Globals.socket.On(Globals.GameID + " ready", async(data) =>
     {
         Globals.socket.Off(Globals.GameID + " ready");
         if ((long)data == Globals.PlayerID)
         {
             Globals.player.HasTurn = true;
         }
         await dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
         {
             Frame.Navigate(typeof(GameScreen));
         });
     });
     Globals.socket.Emit("fleet finished", string.Format("{{\"playerID\": {0}, \"gameID\": {1}}}", Globals.PlayerID, Globals.GameID));
 }
Exemple #9
0
        private void Canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            if (Globals.DrawReady)
            {
                for (int i = 0; i < shipImages.Length; i++)
                {
                    lock (clickedLock)
                    {
                        if (Globals.player.fleet[i] != null)
                        {
                            double x    = Globals.player.fleet[i].mainPoint.X;
                            double y    = Globals.player.fleet[i].mainPoint.Y;
                            float  xPos = (float)Globals.player.homeGrid[(int)x][(int)y].ScreenPoint.X;
                            float  yPos = (float)Globals.player.homeGrid[(int)x][(int)y].ScreenPoint.Y;

                            args.DrawingSession.DrawImage(shipShadows[i], xPos, yPos);
                            args.DrawingSession.DrawImage(shipImages[i], xPos, yPos);
                        }
                    }
                }
                lock (hoverLock)
                {
                    if (hoveredShip != null)
                    {
                        float drawX       = (float)Globals.player.homeGrid[(int)(hoveredShip.mainPoint.X)][(int)(hoveredShip.mainPoint.Y)].ScreenPoint.X;
                        float drawY       = (float)Globals.player.homeGrid[(int)(hoveredShip.mainPoint.X)][(int)(hoveredShip.mainPoint.Y)].ScreenPoint.Y;
                        float imageWidth  = (float)shipImages[hoveredShip.Length - 2].GetBounds(screenCanvas).Width;
                        float imageHeight = (float)shipImages[hoveredShip.Length - 2].GetBounds(screenCanvas).Height;
                        args.DrawingSession.DrawRectangle(drawX, drawY, imageWidth, imageHeight, Windows.UI.Colors.Red, 3);
                        var rotateResult    = hoveredShip.GetRotationPosition();
                        int imageIndex      = Array.IndexOf(shipNames, hoveredShip.ShipName);
                        var transparentShip = new OpacityEffect();
                        if (hoveredShip.Vertical)
                        {
                            transparentShip.Source = horizontalShips[imageIndex];
                        }
                        else
                        {
                            transparentShip.Source = verticalShips[imageIndex];
                        }
                        transparentShip.Opacity = (float)0.6;
                        if (rotateResult.Item1.Length > 0 && rotateResult.Item2)
                        {
                            args.DrawingSession.DrawImage(transparentShip, drawX, drawY);
                        }
                        else if (rotateResult.Item1.Length > 0)
                        {
                            var tintedShip = new TintEffect()
                            {
                                Source = transparentShip,
                                Color  = Windows.UI.Colors.Red
                            };
                            args.DrawingSession.DrawImage(tintedShip, drawX, drawY);
                        }
                    }
                }
                lock (clickedLock)
                {
                    if (moveError != null)
                    {
                        var tintedShip = new TintEffect
                        {
                            Source = shipImages[clickedShip.Length - 2],
                            Color  = Windows.UI.Colors.Red
                        };
                        var transparentShip = new OpacityEffect
                        {
                            Source  = tintedShip,
                            Opacity = (float)0.75
                        };
                        float xPos = (float)Globals.player.homeGrid[(int)moveError.Item1.X][(int)moveError.Item1.Y].ScreenPoint.X;
                        float yPos = (float)Globals.player.homeGrid[(int)moveError.Item1.X][(int)moveError.Item1.Y].ScreenPoint.Y;
                        args.DrawingSession.DrawImage(transparentShip, xPos, yPos);
                    }
                }
            }
        }
Exemple #10
0
        protected void CanvasAnimatedControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            // First, ensure we have exclusive access to the list of sprites. we don't want this changing while we are trying
            // to draw it. If another thread has access to it, we will skip drawing this frame.

            if (Monitor.TryEnter(Sprite.Sprites))
            {
                try
                {
                    // Establish the scale. Normally we draw at 1.0 scale. However, if the drawing surface is SMALLER than our coordinate space, we
                    // need to scale down. Likewise, if we are in fullscreen mode, we'll need to scale up.
                    if (sender.Size.Width < Dimensions.Width || sender.Size.Height < Dimensions.Height || fullscreen)
                    {
                        scale = (float)Math.Min(sender.Size.Width / Dimensions.Width, sender.Size.Height / Dimensions.Height);
                    }
                    else
                    {
                        scale = 1.0f;
                    }

                    // Draw the 'scale' transform into the scene
                    args.DrawingSession.Transform = Matrix3x2.CreateScale(scale, new Vector2((float)(sender.Size.Width / 2), (float)(sender.Size.Height / 2)));

                    // Upper-left corner of the destination drawing space
                    var origin = new Point()
                    {
                        X = (sender.Size.Width - Dimensions.Width) / 2, Y = (sender.Size.Height - Dimensions.Height) / 2
                    };

                    // Rectangle describing the destination drawing space
                    var destrect = new Rect(origin, Dimensions);

                    // Creating a layer around the destination drawing space is how we clip drawing to only the
                    // expected drawing space
                    using (args.DrawingSession.CreateLayer(1.0f, destrect))
                    {
                        // Draw the background
                        if (background != null && bitmaps.ContainsKey(background))
                        {
                            args.DrawingSession.DrawImage(bitmaps[background], destrect);
                        }

                        // The sprites are all positioned relative to the 'center', so we need to know where that is
                        // on the screen right now
                        var center = new Point(sender.Size.Width / 2, sender.Size.Height / 2);

                        // Draw each sprite
                        foreach (var sprite in Sprite.Sprites.OrderBy(x => x.Layer))
                        {
                            // Only draw the sprite if we have a costume loaded for it
                            if (sprite.Costume != null && sprite.Visible && bitmaps.ContainsKey(sprite.Costume))
                            {
                                // Fetch the correct drawing resource for this sprite
                                var bitmap = bitmaps[sprite.Costume];

                                // Figure out how big of space the sprite will occupy in the scene. This is where we
                                // apply sprite scaling. Also, this value is used for collisions.
                                sprite.CostumeSize = new Size(bitmap.Size.Width * sprite.Scale, bitmap.Size.Height * sprite.Scale);

                                // The 'drawme' is the canvas image we will ultimately draw. Along the way we will optionally
                                // apply effects to it.
                                ICanvasImage drawme = bitmap;

                                // Opacity effect if we are not fully opaque
                                if (sprite.Opacity < 1.0)
                                {
                                    drawme = new OpacityEffect()
                                    {
                                        Source  = drawme,
                                        Opacity = (float)sprite.Opacity
                                    };
                                }

                                // Rotation effect if we are rotated.
                                if (sprite.RotationAngle != 0.0)
                                {
                                    drawme = new Transform2DEffect()
                                    {
                                        Source          = drawme,
                                        TransformMatrix = Matrix3x2.CreateRotation((float)sprite.RotationAngle, new Vector2((float)bitmap.Size.Width / 2, (float)bitmap.Size.Height / 2))
                                    };
                                }

                                // Flip horizontal, if so indicated
                                if (sprite.FlipHorizontal)
                                {
                                    drawme = new Transform2DEffect()
                                    {
                                        Source          = drawme,
                                        TransformMatrix = Matrix3x2.CreateScale(-1.0f, 1.0f, new Vector2((float)bitmap.Size.Width / 2, (float)bitmap.Size.Height / 2))
                                    };
                                }

                                // Where in the scene to draw the sprite
                                var draw_at = new Point(center.X + sprite.Position.X - sprite.CostumeSize.Width / 2, center.Y - sprite.Position.Y - sprite.CostumeSize.Height / 2);

                                // Draw the sprite!
                                args.DrawingSession.DrawImage(drawme, new Rect(draw_at, sprite.CostumeSize), new Rect(new Point(0, 0), bitmap.Size));

                                // Render the 'saying'
                                if (sprite.Saying?.Length > 0)
                                {
                                    var drawingSession = args.DrawingSession;
                                    var format         = new CanvasTextFormat {
                                        FontSize = 30.0f, WordWrapping = CanvasWordWrapping.NoWrap
                                    };
                                    var textLayout = new CanvasTextLayout(drawingSession, sprite.Saying, format, 0.0f, 0.0f);

                                    float xcenter = (float)(center.X + sprite.Position.X);
                                    float ytop    = (float)(center.Y - sprite.Position.Y + bitmap.Size.Height / 2 + 10.0);

                                    var theRectYouAreLookingFor = new Rect(xcenter - textLayout.LayoutBounds.Width / 2 - 5, ytop, textLayout.LayoutBounds.Width + 10, textLayout.LayoutBounds.Height);
                                    drawingSession.FillRectangle(theRectYouAreLookingFor, Colors.White);
                                    drawingSession.DrawTextLayout(textLayout, xcenter - (float)textLayout.LayoutBounds.Width / 2, ytop, Colors.Black);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    // This is not a great thing to do with exceptions...
                }
                finally
                {
                    Monitor.Exit(Sprite.Sprites);
                }
            }
        }
Exemple #11
0
        public static async Task <AttachedStaticCompositionEffect <T> > AttachCompositionCustomAcrylicEffectAsync <T>(
            [NotNull] this T element, Color color, float colorMix,
            [CanBeNull] CanvasControl canvas, [NotNull] Uri uri, int timeThreshold = 1000, bool reload = false, bool disposeOnUnload = false)
            where T : FrameworkElement
        {
            // Percentage check
            if (colorMix <= 0 || colorMix >= 1)
            {
                throw new ArgumentOutOfRangeException("The mix factors must be in the [0,1] range");
            }
            if (timeThreshold <= 0)
            {
                throw new ArgumentOutOfRangeException("The time threshold must be a positive number");
            }

            // Setup the compositor
            Visual     visual     = ElementCompositionPreview.GetElementVisual(element);
            Compositor compositor = visual.Compositor;

            // Prepare a luminosity to alpha effect to adjust the background contrast
            CompositionBackdropBrush         hostBackdropBrush   = compositor.CreateHostBackdropBrush();
            CompositionEffectSourceParameter backgroundParameter = new CompositionEffectSourceParameter(nameof(hostBackdropBrush));
            LuminanceToAlphaEffect           alphaEffect         = new LuminanceToAlphaEffect {
                Source = backgroundParameter
            };
            OpacityEffect opacityEffect = new OpacityEffect
            {
                Source  = alphaEffect,
                Opacity = 0.4f // Reduce the amount of the effect to avoid making bright areas completely black
            };

            // Layer [0,1,3] - Desktop background with blur and tint overlay
            BlendEffect alphaBlend = new BlendEffect
            {
                Background = backgroundParameter,
                Foreground = opacityEffect,
                Mode       = BlendEffectMode.Overlay
            };
            IDictionary <String, CompositionBrush> sourceParameters = new Dictionary <String, CompositionBrush>
            {
                { nameof(hostBackdropBrush), hostBackdropBrush }
            };

            // Get the noise brush using Win2D
            IGraphicsEffect source = await AcrylicEffectHelper.ConcatenateEffectWithTintAndBorderAsync(compositor,
                                                                                                       alphaBlend, sourceParameters, color, colorMix, canvas, uri, timeThreshold, reload);

            // Make sure the Win2D brush was loaded correctly
            CompositionEffectFactory factory = compositor.CreateEffectFactory(source);

            // Create the effect factory and apply the final effect
            CompositionEffectBrush effectBrush = factory.CreateBrush();

            foreach (KeyValuePair <String, CompositionBrush> pair in sourceParameters)
            {
                effectBrush.SetSourceParameter(pair.Key, pair.Value);
            }

            // Create the sprite to display and add it to the visual tree
            SpriteVisual sprite = compositor.CreateSpriteVisual();

            sprite.Brush = effectBrush;
            await AddToTreeAndBindSizeAsync(visual, element, sprite);

            return(new AttachedStaticCompositionEffect <T>(element, sprite, disposeOnUnload));
        }
        public CanvasRenderTarget applyEdgeDetectionEffects(CanvasBitmap workingBitmap)
        {
            //CanvasBitmap workingBitmap = SelectWorkingBitmap(useOriginalBitmap);


            if (workingBitmap != null)
            {
                int ww = (int)workingBitmap.SizeInPixels.Width;
                int hh = (int)workingBitmap.SizeInPixels.Height;

                //GrayscaleEffect grayscaleEffect = new GrayscaleEffect();
                //grayscaleEffect.Source=canvasBitmap;

                ContrastEffect contrastEffect = new ContrastEffect();
                contrastEffect.Contrast = (float)edgeDetectionContrast;
                contrastEffect.Source   = workingBitmap;

                ExposureEffect exposureEffect = new ExposureEffect();
                exposureEffect.Source   = contrastEffect;
                exposureEffect.Exposure = (float)edgeDetectionExposure;


                EdgeDetectionEffect edgeDetectionEffect = new EdgeDetectionEffect();
                edgeDetectionEffect.Source     = exposureEffect;
                edgeDetectionEffect.Amount     = (float)edgeDetectionAmount;
                edgeDetectionEffect.BlurAmount = (float)edgeDetectionBlurAmount;
                //edgeDetectionEffect.OverlayEdges = true;
                //edgeDetectionEffect.Mode = EdgeDetectionEffectMode.Prewitt;

                GrayscaleEffect grayscaleEffect = null;
                if (edgeDetectionGrayscale)
                {
                    grayscaleEffect            = new GrayscaleEffect();
                    grayscaleEffect.Source     = exposureEffect;
                    edgeDetectionEffect.Source = grayscaleEffect;
                }

                InvertEffect invertEdgeEffect = null;
                if (edgeDetectionMaskInvert)
                {
                    invertEdgeEffect        = new InvertEffect();
                    invertEdgeEffect.Source = edgeDetectionEffect;
                }



                BlendEffect blendEffect = null;
                if (edgeDetectionOverlayImage)
                {
                    OpacityEffect opacityEffect = new OpacityEffect();
                    opacityEffect.Opacity = (float)edgeDetectionOverlayOpacity;
                    opacityEffect.Source  = workingBitmap;

                    blendEffect            = new BlendEffect();
                    blendEffect.Foreground = edgeDetectionEffect;
                    blendEffect.Background = opacityEffect;
                    if (edgeDetectionMaskInvert)
                    {
                        //blendEffect.Background = invertEdgeEffect;
                        //blendEffect.Foreground = opacityEffect;

                        InvertEffect invertOrgEffect = new InvertEffect();
                        invertOrgEffect.Source = opacityEffect;
                        blendEffect.Background = invertOrgEffect;
                    }

                    blendEffect.Mode = edgeDetectionBlendEffectMode;
                }


                //if (canvasRenderTarget != null)
                //    canvasRenderTarget.Dispose();
                CanvasRenderTarget canvasRenderTarget = new CanvasRenderTarget(CanvasDevice.GetSharedDevice(), ww, hh, canvasBitmap.Dpi);
                using (var session = canvasRenderTarget.CreateDrawingSession())
                {
                    if (edgeDetectionOverlayImage)
                    {
                        session.DrawImage(blendEffect);
                    }
                    else
                    {
                        if (edgeDetectionMaskInvert)
                        {
                            session.DrawImage(invertEdgeEffect);
                        }
                        else
                        {
                            session.DrawImage(edgeDetectionEffect);
                        }
                    }
                }

                return(canvasRenderTarget);
            }

            return(null);
        }