Ejemplo n.º 1
0
        private static IReadOnlyList <IImageProvider> CreateFramedAnimation(IReadOnlyList <IImageProvider> images, Rect animationBounds, int w, int h)
        {
            List <IImageProvider> framedAnimation = new List <IImageProvider>();

            WriteableBitmap maskBitmap = new WriteableBitmap(w, h);

            var backgroundRectangle = new Rectangle
            {
                Fill   = new SolidColorBrush(Colors.Black),
                Width  = w,
                Height = h,
            };

            maskBitmap.Render(backgroundRectangle, new TranslateTransform());

            var foregroundRectangle = new Rectangle
            {
                Fill   = new SolidColorBrush(Colors.White),
                Width  = animationBounds.Width,
                Height = animationBounds.Height,
            };

            TranslateTransform foregroundTranslate = new TranslateTransform();

            foregroundTranslate.X = animationBounds.X;
            foregroundTranslate.Y = animationBounds.Y;
            maskBitmap.Render(foregroundRectangle, foregroundTranslate);
            maskBitmap.Invalidate();

            foreach (IImageProvider frame in images)
            {
                FilterEffect filterEffect = new FilterEffect(images[0]);

                ImageFusionFilter imageFusionFilter = new ImageFusionFilter(frame, new BitmapImageSource(maskBitmap.AsBitmap()), false);

                filterEffect.Filters = new List <IFilter>()
                {
                    imageFusionFilter
                };
                framedAnimation.Add(filterEffect);
            }

            return(framedAnimation);
        }
Ejemplo n.º 2
0
        private static IReadOnlyList<IImageProvider> CreateFramedAnimation(IReadOnlyList<IImageProvider> images, Rect animationBounds, int w, int h)
        {
            List<IImageProvider> framedAnimation = new List<IImageProvider>();

            WriteableBitmap maskBitmap = new WriteableBitmap(w, h);

            var backgroundRectangle = new Rectangle
            {
                Fill = new SolidColorBrush(Colors.Black),
                Width = w,
                Height = h,
            };

            maskBitmap.Render(backgroundRectangle, new TranslateTransform());

            var foregroundRectangle = new Rectangle
            {
                Fill = new SolidColorBrush(Colors.White),
                Width = animationBounds.Width,
                Height = animationBounds.Height,
            };

            TranslateTransform foregroundTranslate = new TranslateTransform();
            foregroundTranslate.X = animationBounds.X;
            foregroundTranslate.Y = animationBounds.Y;
            maskBitmap.Render(foregroundRectangle, foregroundTranslate);
            maskBitmap.Invalidate();

            foreach (IImageProvider frame in images)
            {
                FilterEffect filterEffect = new FilterEffect(images[0]);

                ImageFusionFilter imageFusionFilter = new ImageFusionFilter(frame, new BitmapImageSource(maskBitmap.AsBitmap()), false);

                filterEffect.Filters = new List<IFilter>() { imageFusionFilter };
                framedAnimation.Add(filterEffect);
            }

            return framedAnimation;
        }