private static ICanvasImage CreateColorMatrixEffect(ICanvasImage canvasImage, float coeff)
        {
            var ef = new ColorMatrixEffect
            {
                Source = canvasImage
            };

            var matrix = new Matrix5x4();

            matrix.M11 = (float)Math.Sin(coeff * 1.5);
            matrix.M21 = (float)Math.Sin(coeff * 1.4);
            matrix.M31 = (float)Math.Sin(coeff * 1.3);
            matrix.M51 = (1 - matrix.M11 - matrix.M21 - matrix.M31) / 2;

            matrix.M12 = (float)Math.Sin(coeff * 1.2);
            matrix.M22 = (float)Math.Sin(coeff * 1.1);
            matrix.M32 = (float)Math.Sin(coeff * 1.0);
            matrix.M52 = (1 - matrix.M12 - matrix.M22 - matrix.M32) / 2;

            matrix.M13 = (float)Math.Sin(coeff * 0.9);
            matrix.M23 = (float)Math.Sin(coeff * 0.8);
            matrix.M33 = (float)Math.Sin(coeff * 0.7);
            matrix.M53 = (1 - matrix.M13 - matrix.M23 - matrix.M33) / 2;

            matrix.M44 = 1;

            ef.ColorMatrix = matrix;

            return(ef);
        }
Example #2
0
        async Task canvas_CreateResourcesAsync(CanvasAnimatedControl sender)
        {
            DissolveEffect = new PixelShaderEffect(await ReadAllBytes("Assets/Shaders/WipeUp.bin"));
            //DissolveEffect.Properties["feather"] = 0.1f;
            DissolveMask = await CreateRippleEffect();

            CanvasSourceImageLarge1 = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///" + "Assets/Images/beautiful-bloom-blooming-blossom-414083.jpg"));

            CanvasSourceImageLarge2 = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///" + "Assets/Images/nature-red-forest-leaves-33109.jpg"));

            CanvasSourceImageSmall1 = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///" + "Assets/Images/beach-birds-calm-clouds-219998.jpg"));

            CanvasSourceImageSmall2 = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///" + "Assets/Images/photography-of-trees-covered-with-snow-773594.jpg"));

            try
            {
                var info = Windows.Graphics.Display.DisplayInformation.GetForCurrentView();
                DissolveEffect.Properties["dpi"]    = info.LogicalDpi;
                DissolveEffect.Properties["height"] = 369f;
                //DissolveEffect.Properties["progress"] = (float)ProgressSlider.Value;
                DissolveEffect.Source1 = CanvasSourceImageSmall1;
                //DissolveEffect.Source2 = CanvasSourceImageSmall2;
            }
            catch { }
        }
        private static ICanvasImage CreateGrayscaleEffect(ICanvasImage canvasImage)
        {
            var ef = new GrayscaleEffect();

            ef.Source = canvasImage;
            return(ef);
        }
Example #4
0
 public ICanvasImage GetRender(ICanvasImage image)
 {
     return(new InvertEffect
     {
         Source = image
     });
 }
Example #5
0
 public ICanvasImage ApplyFilter(ICanvasImage source)
 {
     return(new InvertEffect
     {
         Source = source
     });
 }
Example #6
0
 private async void LoadImage1(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 {
     bitmap1 = new SepiaEffect
     {
         Source = await PickImageAsync()
     };
 }
        public ICanvasImage GetRender(ICanvasImage image)
        {
            return(new GammaTransferEffect
            {
                ClampOutput = this.ClampOutput,

                AlphaDisable = this.AlphaDisable,
                AlphaOffset = this.AlphaOffset,
                AlphaExponent = this.AlphaExponent,
                AlphaAmplitude = this.AlphaAmplitude,

                RedDisable = this.RedDisable,
                RedOffset = this.RedOffset,
                RedExponent = this.RedExponent,
                RedAmplitude = this.RedAmplitude,

                GreenDisable = this.GreenDisable,
                GreenOffset = this.GreenOffset,
                GreenExponent = this.GreenExponent,
                GreenAmplitude = this.GreenAmplitude,

                BlueDisable = this.BlueDisable,
                BlueOffset = this.BlueOffset,
                BlueExponent = this.BlueExponent,
                BlueAmplitude = this.BlueAmplitude,

                Source = image
            });
        }
Example #8
0
        public static ICanvasImage GetShadow(ICanvasImage canvasImage, float BlurAmount, Color ShadowColor, float X, float Y)
        {
            if (BlurAmount < 0)
            {
                BlurAmount = 0;
            }
            else if (BlurAmount > 100)
            {
                BlurAmount = 100;
            }

            return(new CompositeEffect
            {
                Sources =
                {
                    new Transform2DEffect
                    {
                        Source = new ShadowEffect
                        {
                            Source = canvasImage,
                            BlurAmount = BlurAmount,
                            ShadowColor = ShadowColor,
                        },
                        TransformMatrix = Matrix3x2.CreateTranslation(X, Y),
                    },
                    canvasImage
                }
            });
        }
Example #9
0
        //冷暖方法
        public static ICanvasImage GetTemperature(ICanvasImage canvasImage, float Temperature, float Tint = 0f)
        {
            if (Temperature < -1)
            {
                Temperature = -1;
            }
            else if (Temperature > 1)
            {
                Temperature = 1;
            }
            if (Tint < -1)
            {
                Tint = -1;
            }
            else if (Tint > 1)
            {
                Tint = 1;
            }

            return(new TemperatureAndTintEffect
            {
                Source = canvasImage,
                Temperature = Temperature,
                Tint = Tint,
            });
        }
Example #10
0
        //边界算法
        public static ICanvasImage GetBorder(ICanvasImage canvasImage, int Border)
        {
            if (Border == 0)
            {
                return(canvasImage);
            }
            else if (Border >= 90)
            {
                Border = 90;
            }
            else if (Border <= -90)
            {
                Border = -90;
            }

            return(new MorphologyEffect//形态学
            {
                Source = new BorderEffect {
                    Source = canvasImage
                },                                                                              //边界效应
                Mode = (Border > 0) ? MorphologyEffectMode.Dilate : MorphologyEffectMode.Erode, //扩张&侵蚀
                Height = Math.Abs(Border),
                Width = Math.Abs(Border)                                                        //地区扩张
            });
        }
Example #11
0
        void CreateTurbulence()
        {
            turbulence = new ColorMatrixEffect
            {
                Source = new TurbulenceEffect
                {
                    Size      = tigerSize,
                    Frequency = new Vector2(0.02f),
                    Octaves   = 3,
                },

                // Adjust intensity of the generated turbulence, and copy the red channel over green and blue.
                ColorMatrix = new Matrix5x4
                {
                    M11 = 1.8f,
                    M12 = 1.8f,
                    M13 = 1.8f,

                    M51 = -0.4f,
                    M52 = -0.4f,
                    M53 = -0.4f,

                    M54 = 1
                }
            };
        }
Example #12
0
 public static void Erasing(this CanvasDrawingSession session, ICanvasImage mask, float o = 1)
 {
     session.DrawImage(
         mask, mask.GetBounds(session.Device), mask.GetBounds(session.Device),
         o, CanvasImageInterpolation.Linear, CanvasComposite.DestinationOut
         );
 }
Example #13
0
 private ICanvasImage image2Premultiply(ICanvasImage aImage)
 {
     return(new PremultiplyEffect()
     {
         Source = aImage
     });
 }
Example #14
0
        //浮雕方法
        public static ICanvasImage GetEmboss(ICanvasImage canvasImage, float Amount, float Angle)
        {
            if (Amount < 0)
            {
                Amount = 0;
            }
            else if (Amount > 10)
            {
                Amount = 10;
            }

            if (Angle < 0)
            {
                Angle = 0;
            }
            else if (Angle > 2 * (float)(Math.PI))
            {
                Angle = (float)(2 * Math.PI);
            }

            return(new EmbossEffect
            {
                Source = canvasImage,
                Amount = Amount,
                Angle = Angle,
            });
        }
 public ICanvasImage GetRender(ICanvasImage image)
 {
     return(new GrayscaleEffect
     {
         Source = image
     });
 }
Example #16
0
 public ICanvasImage ApplyFilter(ICanvasImage source)
 {
     return(new GrayscaleEffect
     {
         Source = source
     });
 }
Example #17
0
        //初始化杂项渲染目标
        public static void InitializeOther()
        {
            //下杂项渲染目标 (从灰白网格到当前图层)
            using (CanvasDrawingSession ds = App.Model.SecondBottomRenderTarget.CreateDrawingSession())
            {
                ICanvasImage ci = App.GrayWhiteGrid;                                //由下向上渲染的图片接口

                for (int i = App.Model.Layers.Count - 1; i >= App.Model.Index; i--) //自下而上渲染
                {
                    ci = App.Render(App.Model.Layers[i], ci);                       //渲染
                }
                ds.DrawImage(ci);
            }

            //上杂项渲染目标 (从当前图层的的上一层到顶层)
            using (CanvasDrawingSession ds = App.Model.SecondTopRenderTarget.CreateDrawingSession())
            {
                ds.Clear(Colors.Transparent);

                ICanvasImage ci = App.Model.NullRenderTarget;

                //当前图层索引不在0,即并不在第一层
                if (App.Model.Index > 0)
                {
                    for (int i = 0; i < App.Model.Index; i++)     //自上而下渲染
                    {
                        ci = App.Render(App.Model.Layers[i], ci); //渲染
                    }
                    ds.DrawImage(ci);
                }
            }
        }
Example #18
0
        public override ICanvasImage GetRender(ICanvasResourceCreator resourceCreator, Layerage layerage)
        {
            if (layerage.Children.Count == 0)
            {
                return(null);
            }

            ICanvasImage childImage = LayerBase.Render(resourceCreator, layerage);

            if (childImage is null)
            {
                return(null);
            }

            CanvasCommandList command = new CanvasCommandList(resourceCreator);

            using (CanvasDrawingSession drawingSession = command.CreateDrawingSession())
            {
                if (this.Transform.IsCrop)
                {
                    CanvasGeometry geometryCrop = this.Transform.CropTransformer.ToRectangle(resourceCreator);

                    using (drawingSession.CreateLayer(1, geometryCrop))
                    {
                        drawingSession.DrawImage(childImage);
                    }
                }
                else
                {
                    drawingSession.DrawImage(childImage);
                }
            }
            return(command);
        }
Example #19
0
        public static ICanvasImage GetTint(ICanvasImage canvasImage, float Opacity, Color Color)
        {
            if (Opacity < 0)
            {
                Opacity = 0;
            }
            else if (Opacity > 1)
            {
                Opacity = 1;
            }

            return(new CompositeEffect
            {
                Sources =
                {
                    canvasImage,
                    new OpacityEffect
                    {
                        Opacity = Opacity,
                        Source = new TintEffect
                        {
                            Source = canvasImage,
                            Color = Color
                        }
                    }
                }
            });
        }
Example #20
0
 private void Canvas_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (canvas.ReadyToDraw)
     {
         effect = CreateEffect();
     }
 }
Example #21
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
                },
            };
        }
Example #22
0
        //边缘检测方法
        public static ICanvasImage GetEdgeDetection(ICanvasImage canvasImage, float Amount, float BlurAmount = 0, EdgeDetectionEffectMode Mode = EdgeDetectionEffectMode.Sobel, CanvasAlphaMode AlphaMode = CanvasAlphaMode.Premultiplied, bool OverlayEdges = false)
        {
            if (Amount < 0)
            {
                Amount = 0;
            }
            else if (Amount > 1)
            {
                Amount = 1;
            }
            if (BlurAmount < 0)
            {
                BlurAmount = 0;
            }
            else if (BlurAmount > 10)
            {
                BlurAmount = 10;
            }

            return(new EdgeDetectionEffect
            {
                Source = canvasImage,

                Amount = Amount,
                BlurAmount = BlurAmount,

                Mode = Mode,
                AlphaMode = AlphaMode,
                OverlayEdges = OverlayEdges,
            });
        }
Example #23
0
 static void ValidateCannotDrawImage(CanvasDevice device, ICanvasImage image)
 {
     ValidateUnsupportedPixelFormatException(() =>
     {
         ValidateCanDrawImage(device, image);
     });
 }
Example #24
0
        //Merge Visual:合并可见
        private void LayerMergeVisualButton_Click(object sender, RoutedEventArgs e)
        {
            App.Model.isCanUndo = false;//关闭撤销

            //更新撤销类
            Undo undo = new Undo();

            undo.CollectionInstantiation(App.Model.Index, App.Model.Layers);
            App.UndoAdd(undo);


            //新建渲染目标=>层
            CanvasRenderTarget crt = new CanvasRenderTarget(App.Model.VirtualControl, App.Model.Width, App.Model.Height);

            using (CanvasDrawingSession ds = crt.CreateDrawingSession())
            {
                ds.Clear(Colors.Transparent);

                ICanvasImage ci = App.Model.NullRenderTarget;
                for (int i = App.Model.Layers.Count - 1; i >= 0; i--) //自下而上渲染
                {
                    ci = App.Render(App.Model.Layers[i], ci);         //渲染
                }
                ds.DrawImage(ci);
            }

            //删掉所有可视图层
            for (int i = App.Model.Layers.Count - 1; i >= 0; i--)//自下而上
            {
                Layer L = App.Model.Layers[i];
                if (L.Visual == true)
                {
                    App.Model.Layers.Remove(L);
                }
            }

            //插入与索引
            Layer l = new Layer {
                Name = App.resourceLoader.GetString("/Layer/NameMerge_"), Visual = true, Opacity = 100, CanvasRenderTarget = crt,
            };

            if (App.Model.isLowView)
            {
                l.LowView();
            }
            else
            {
                l.SquareView();
            }

            l.SetWriteableBitmap(App.Model.VirtualControl);//刷新缩略图
            App.Model.Layers.Insert(0, l);
            App.Model.Index = 0;

            App.Model.isCanUndo   = true;                   //打开撤销
            App.Model.LayersCount = App.Model.Layers.Count; //Undo:撤销

            Jugde();                                        //判断
        }
 public ICanvasImage GetRender(ICanvasImage image)
 {
     return(new ColorMatrixEffect
     {
         Source = image,
         ColorMatrix = AdjustmentExtensions.GetColorMatching(this.SourceColor, this.DestinationColor)
     });
 }
Example #26
0
 public ICanvasImage GetRender(ICanvasImage image)
 {
     return(new SaturationEffect
     {
         Saturation = this.Saturation,
         Source = image
     });
 }
Example #27
0
        protected override void DrawModification(ref ICanvasImage bitmap, CanvasDrawingSession draw)
        {
            base.DrawModification(ref bitmap, draw);

            //Rotates the player in the direction where he is moving
            //(this is implemented automatically within a list in the AbstractActor)
            //RotationStrategy.DrawModification(ref bitmap, draw);
        }
Example #28
0
        public void Dispose()
        {
            _cl?.Dispose();
            _cl = null;

            shadow?.Dispose();
            shadow = null;
        }
Example #29
0
 public ICanvasImage GetRender(ICanvasImage image)
 {
     return(new HueRotationEffect
     {
         Angle = this.Angle,
         Source = image
     });
 }
Example #30
0
 public void Setup(ICanvasImage canvas, double amount = 10)
 {
     morphology.Source = canvas;
     amount            = Math.Min(amount / 2, 100);
     morphology.Width  = (int)Math.Truncate(Math.Floor(amount));
     morphology.Height = (int)Math.Truncate(Math.Floor(amount));
     Blur.BlurAmount   = (float)amount;
 }
 public ICanvasImage GetRender(ICanvasImage image)
 {
     return(new ExposureEffect
     {
         Exposure = this.Exposure,
         Source = image
     });
 }
Example #32
0
 public void Dispose()
 {
     _cl?.Dispose();
     _cl = null;
     morphology?.Dispose();
     morphology = null;
     blur?.Dispose();
     blur = null;
 }
Example #33
0
        public void Setup(ICanvasImage source, float amount)
        {
            morphology.Source = source;

            var halfAmount = Math.Min(amount / 2, 100);
            morphology.Width = (int)Math.Ceiling(halfAmount);
            morphology.Height = (int)Math.Ceiling(halfAmount);
            blur.BlurAmount = halfAmount;
        }
Example #34
0
        private void _setup(ICanvasImage source, float amount, Color shadowColor)
        {

            if (_cl != null) { _cl.Dispose(); _cl = null; }
            _cl = source;

            shadow.Source = _cl;
            shadow.BlurAmount = amount;
            shadow.ShadowColor = shadowColor;
        }
Example #35
0
        private void _setup(ICanvasImage source, float amount)
        {
            if (amount == 0) return;

            if (_cl != null) { _cl.Dispose(); _cl = null; }
            _cl = source;

            morphology.Source = _cl;
            
            var halfAmount = Math.Min(amount / 2, 100);
            morphology.Width = (int)Math.Ceiling(halfAmount);
            morphology.Height = (int)Math.Ceiling(halfAmount);
            blur.BlurAmount = halfAmount;
        }
Example #36
0
        public ICanvasImage Cache(Photo photo, ICanvasImage image, params object[] keys)
        {
            if (cachedImage == null)
            {
                cachedImage = new CanvasRenderTarget(photo.SourceBitmap.Device, photo.Size.X, photo.Size.Y, 96);
            }

            using (var drawingSession = cachedImage.CreateDrawingSession())
            {
                drawingSession.Blend = CanvasBlend.Copy;
                drawingSession.DrawImage(image);
            }

            isCacheValid = true;
            cacheKeys = keys;

            return cachedImage;
        }
Example #37
0
        async Task LoadBitmaps(CanvasControl sender)
        {
            var bitmapType = CurrentBitmapType;
            var bitmapSource = CurrentBitmapSource;

            var newTestBitmaps = new ICanvasImage[fileNames.Length];

            for (int i = 0; i < fileNames.Length; i++)
            {
                Package package = Package.Current;
                StorageFolder installedLocation = package.InstalledLocation;
                string pathName = installedLocation.Path + "\\" + "BitmapOrientation" + "\\" + fileNames[i];

                if (bitmapSource == BitmapSourceOption.FromStream)
                {
                    StorageFile storageFile = await StorageFile.GetFileFromPathAsync(pathName);
                    using (IRandomAccessStreamWithContentType stream = await storageFile.OpenReadAsync())
                    {
                        if (bitmapType == BitmapType.CanvasBitmap)
                            newTestBitmaps[i] = await CanvasBitmap.LoadAsync(sender, stream);
#if WINDOWS_UWP
                        else
                            newTestBitmaps[i] = await CanvasVirtualBitmap.LoadAsync(sender, stream);
#endif
                    }
                }
                else
                {
                    if (bitmapType == BitmapType.CanvasBitmap)
                        newTestBitmaps[i] = await CanvasBitmap.LoadAsync(sender, pathName);
#if WINDOWS_UWP
                    else
                        newTestBitmaps[i] = await CanvasVirtualBitmap.LoadAsync(sender, pathName);
#endif
                }
            }

            testBitmaps = newTestBitmaps;
        }
Example #38
0
        private ICanvasImage CombineDiffuseAndSpecular(ICanvasImage diffuse, ICanvasImage specular, float x, float y)
        {
            var composite = new ArithmeticCompositeEffect
            {
                Source1 = new ArithmeticCompositeEffect
                {
                    Source1 = bitmapTiger,
                    Source2 = diffuse,
                    Source1Amount = 0,
                    Source2Amount = 0,
                    MultiplyAmount = 1,
                },
                Source2 = specular,
                Source1Amount = 1,
                Source2Amount = 1,
                MultiplyAmount = 0,
            };

            return AddTextOverlay(composite, x, y);
        }
Example #39
0
        private ICanvasImage AddTextOverlay(ICanvasImage effect, float x, float y)
        {
            var textOverlay = new CanvasRenderTarget(canvas, 200, 30);

            using (var ds = textOverlay.CreateDrawingSession())
            {
                ds.Clear(Color.FromArgb(0, 0, 0, 0));
                ds.DrawText(effect.GetType().Name.Replace("Effect", ""), 0, 0, Colors.White);
            }

            return new Transform2DEffect
            {
                Source = new BlendEffect
                {
                    Background = effect,
                    Foreground = textOverlay,
                    Mode = BlendEffectMode.Screen
                },
                TransformMatrix = Matrix3x2.CreateTranslation(x, y)
            };
        }
Example #40
0
        private void CreateEffect(bool resetTime = true)
        {
            if (resetTime)
            {
                timer = Stopwatch.StartNew();
            }

            currentEffectSize = bitmapTiger.Size.ToVector2();
            textLabel = null;

            switch (CurrentEffect)
            {
                case EffectType.ArithmeticComposite:
                    effect = CreateArithmeticComposite();
                    break;

                case EffectType.Blend:
                    effect = CreateBlend();
                    break;

                case EffectType.Border:
                    effect = CreateBorder();
                    break;

                case EffectType.Brightness:
                    effect = CreateBrightness();
                    break;

                case EffectType.ColorMatrix:
                    effect = CreateColorMatrix();
                    break;

                case EffectType.Composite:
                    effect = CreateComposite();
                    break;

                case EffectType.ConvolveMatrix:
                    effect = CreateConvolveMatrix();
                    break;

                case EffectType.Crop:
                    effect = CreateCrop();
                    break;

                case EffectType.DirectionalBlur:
                    effect = CreateDirectionalBlur();
                    break;

                case EffectType.DiscreteTransfer:
                    effect = CreateDiscreteTransfer();
                    break;

                case EffectType.DisplacementMap:
                    effect = CreateDisplacementMap();
                    break;

                case EffectType.GaussianBlur:
                    effect = CreateGaussianBlur();
                    break;

                case EffectType.HueRotation:
                    effect = CreateHueRotation();
                    break;

                case EffectType.Lighting:
                    effect = CreateLighting();
                    break;

                case EffectType.LuminanceToAlpha:
                    effect = CreateLuminanceToAlpha();
                    break;

                case EffectType.Morphology:
                    effect = CreateMorphology();
                    break;

                case EffectType.Saturation:
                    effect = CreateSaturation();
                    break;

                case EffectType.Shadow:
                    effect = CreateShadow();
                    break;

                case EffectType.Tile:
                    effect = CreateTile();
                    break;

                case EffectType.Transform3D:
                    effect = CreateTransform3D();
                    break;

#if WINDOWS_UWP
                // The following effects are new in the Universal Windows Platform.
                // They are not supported on Windows 8.1 or Phone 8.1.";

                case EffectType.ChromaKey:
                    effect = CreateChromaKey();
                    break;

                case EffectType.Contrast:
                    effect = CreateContrast();
                    break;

                case EffectType.EdgeDetection:
                    effect = CreateEdgeDetection();
                    break;

                case EffectType.Emboss:
                    effect = CreateEmboss();
                    break;

                case EffectType.Exposure:
                    effect = CreateExposure();
                    break;

                case EffectType.Grayscale:
                    effect = CreateGrayscale();
                    break;

                case EffectType.HighlightsAndShadows:
                    effect = CreateHighlightsAndShadows();
                    break;

                case EffectType.Invert:
                    effect = CreateInvert();
                    break;

                case EffectType.Posterize:
                    effect = CreatePosterize();
                    break;

                case EffectType.RgbToHue:
                    effect = CreateRgbToHue();
                    break;

                case EffectType.Sepia:
                    effect = CreateSepia();
                    break;

                case EffectType.Sharpen:
                    effect = CreateSharpen();
                    break;

                case EffectType.Straighten:
                    effect = CreateStraighten();
                    break;

                case EffectType.TemperatureAndTint:
                    effect = CreateTemperatureAndTint();
                    break;

                case EffectType.Vignette:
                    effect = CreateVignette();
                    break;

#endif  // WINDOWS_UWP

                default:
                    throw new NotSupportedException();
            }

            activeEffectNames = GetActiveEffectNames();
        }
Example #41
0
 public static void DrawImage(this CanvasDrawingSession session, ICanvasImage image, float opacity)
 {
     var rect = image.GetBounds(session);
     session.DrawImage(image, rect, rect, opacity);
 }
Example #42
0
        private ICanvasImage AddSoftEdgedCrop(ICanvasImage effect)
        {
            var size = bitmapTiger.Size;

            var softEdge = new GaussianBlurEffect
            {
                Source = new CropEffect
                {
                    Source = new ColorSourceEffect { Color = Colors.Black },
                    SourceRectangle = new Rect(-size.Width / 2, -size.Height / 2, size.Width * 2, size.Height * 2)
                },
                BlurAmount = 32
            };

            return new CompositeEffect
            {
                Sources = { softEdge, effect },
                Mode = CanvasComposite.SourceIn 
            };
        }
Example #43
0
 static void ValidateCanDrawImage(CanvasDevice device, ICanvasImage image)
 {
     using (var commandList = new CanvasCommandList(device))
     using (var drawingSession = commandList.CreateDrawingSession())
     {
         drawingSession.DrawImage(image);
     }
 }
Example #44
0
        public ICanvasImage Apply(ICanvasImage image, ref Rect? bounds)
        {
            if (!IsEnabled)
                return image;

            var metadata = EffectMetadata.Get(type);

            // Instantiate the effect.
            var effect = (ICanvasImage)Activator.CreateInstance(metadata.ImplementationType);

            // Set the effect input.
            SetProperty(effect, "Source", image);

            // Set configurable parameter values.
            foreach (var parameter in metadata.Parameters)
            {
                var value = GetParameter(parameter);

                SetProperty(effect, parameter.Name, value);

                // Track the image bounds if cropping changes them.
                if (this.Type == EffectType.Crop && parameter.Name == "SourceRectangle")
                {
                    bounds = bounds.HasValue ? RectHelper.Intersect(bounds.Value, (Rect)value) : (Rect)value;
                }
            }

            // Set any constant values.
            foreach (var constant in metadata.Constants)
            {
                SetProperty(effect, constant.Key, constant.Value);
            }

            return effect;
        }
        async Task CreateResourcesAsync(CanvasControl sender)
        {
            bitmap = await CanvasBitmap.LoadAsync(sender, (this.DataContext as PodcastDetailsViewModel).Podcast.Podcast.ImageUrl);

            effect = CreateEffect();
        }
Example #46
0
 public void Setup(ICanvasImage source, params dynamic[] args)
 {
     _setup(source, args[0]);
 }
 private ICanvasImage image2Premultiply(ICanvasImage aImage)
 {
     return new PremultiplyEffect()
     {
         Source = aImage
     };
 }
Example #48
0
        void CreateTurbulence()
        {
            turbulence = new LinearTransferEffect
            {
                Source = new TurbulenceEffect
                {
                    Size = bitmapSize,
                    Frequency = new Vector2(0.02f),
                    Octaves = 3,
                },

                RedSlope = 2,
                RedOffset = -0.2f,
            };
        }
Example #49
0
        ICanvasImage GetSelectionBorder(ICanvasImage mask, float zoomFactor)
        {
            // Scale so our border will always be the same width no matter how the image is zoomed.
            var scaleToCurrentZoom = new ScaleEffect
            {
                Source = mask,
                Scale = new Vector2(zoomFactor)
            };

            // Find edges of the selection.
            var detectEdges = new EdgeDetectionEffect
            {
                Source = scaleToCurrentZoom,
                Amount = 0.1f
            };

            // Colorize.
            var colorItMagenta = new ColorMatrixEffect
            {
                Source = detectEdges,

                ColorMatrix = new Matrix5x4
                {
                    M11 = 1,
                    M13 = 1,
                    M14 = 1,
                }
            };

            // Scale back to the original size.
            return new ScaleEffect
            {
                Source = colorItMagenta,
                Scale = new Vector2(1 / zoomFactor)
            };
        }
        void CreateTurbulence()
        {
            turbulence = new ColorMatrixEffect
            {
                Source = new TurbulenceEffect
                {
                    Size = tigerSize,
                    Frequency = new Vector2(0.02f),
                    Octaves = 3,
                },

                // Adjust intensity of the generated turbulence, and copy the red channel over green and blue.
                ColorMatrix = new Matrix5x4
                {
                    M11 = 1.8f,
                    M12 = 1.8f,
                    M13 = 1.8f,

                    M51 = -0.4f,
                    M52 = -0.4f,
                    M53 = -0.4f,

                    M54 = 1
                }
            };
        }
Example #51
0
 static void ValidateCannotDrawImage(CanvasDevice device, ICanvasImage image)
 {
     ValidateUnsupportedPixelFormatException(() =>
     {
         ValidateCanDrawImage(device, image);
     });
 }
Example #52
0
        public ICanvasImage Apply(ICanvasImage image)
        {
            if (IsEnabled)
            {
                var originalImage = image;
                Rect? bounds = null;

                // Apply all our effects in turn.
                foreach (var effect in Effects)
                {
                    image = effect.Apply(image, ref bounds);
                }

                // Mask so these effects only alter a specific region of the image?
                if (regionMask != null)
                {
                    var selectedRegion = new CompositeEffect
                    {
                        Sources = { image, GetRegionMask() },
                        Mode = CanvasComposite.DestinationIn
                    };

                    image = new CompositeEffect
                    {
                        Sources = { originalImage, selectedRegion }
                    };

                    if (bounds.HasValue)
                    {
                        image = new CropEffect
                        {
                            Source = image,
                            SourceRectangle = bounds.Value
                        };
                    }
                }
            }

            return image;
        }
Example #53
0
 public RainyDay(CanvasAnimatedControl _canvas, float _width, float _height, ICanvasImage _img)
 {
     random = new Random();
     //prepare width and height of region
     width = _width;
     height = _height;
     //prepare imgReflected
     img = _img;
     //prepare drops
     drops = new List<Drop>();
     // assume defaults
     //  trail = Trail_Drops;
  
     CurrentGravity = GravityType.Gravity_Linear;
     collision = Collision_Sample;
     reflection = Reflection_Miniature;
 }