Esempio n. 1
0
        private void OnDraw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (_bitmap == null || _animation == null || _unloaded)
            {
                return;
            }

            args.DrawingSession.DrawImage(_bitmap, new Rect(0, 0, sender.Size.Width, sender.Size.Height));

            if (_hideThumbnail)
            {
                _hideThumbnail = false;

                FirstFrameRendered?.Invoke(this, EventArgs.Empty);
                ElementCompositionPreview.SetElementChildVisual(this, null);
            }

            Monitor.Enter(_subscribeLock);
            if (_unsubscribe)
            {
                _unsubscribe = false;
                Monitor.Exit(_subscribeLock);
                Subscribe(false);
            }
            else
            {
                Monitor.Exit(_subscribeLock);
            }
        }
Esempio n. 2
0
        protected override void DrawFrame(CanvasImageSource sender, CanvasDrawingSession args)
        {
            if (_bitmap == null || _animation == null || _unloaded)
            {
                return;
            }

            if (_flipped)
            {
                args.Transform = Matrix3x2.CreateScale(-1, 1, sender.Size.ToVector2() / 2);
            }

            if (sender.Size.Width >= _bitmap.Size.Width || sender.Size.Height >= _bitmap.Size.Height)
            {
                args.DrawImage(_bitmap,
                               new Rect(0, 0, sender.Size.Width, sender.Size.Height));
            }
            else
            {
                args.DrawImage(_bitmap,
                               new Rect(0, 0, sender.Size.Width, sender.Size.Height),
                               new Rect(0, 0, _bitmap.Size.Width, _bitmap.Size.Height), 1,
                               CanvasImageInterpolation.MultiSampleLinear);
            }

            if (_hideThumbnail)
            {
                _hideThumbnail = false;

                FirstFrameRendered?.Invoke(this, EventArgs.Empty);
                ElementCompositionPreview.SetElementChildVisual(this, null);
            }
        }
Esempio n. 3
0
        private void OnDraw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (_bitmaps != null)
            {
                for (int i = 0; i < _bitmaps.Length; i++)
                {
                    if (_bitmaps[i] != null)
                    {
                        args.DrawingSession.DrawImage(_bitmaps[i], new Rect(0, 0, sender.Size.Width, sender.Size.Height));
                    }
                    else if (i == 1)
                    {
                        return;
                    }
                }

                if (_hideThumbnail)
                {
                    _hideThumbnail = false;
                    FirstFrameRendered?.Invoke(this, EventArgs.Empty);
                }
            }

            Monitor.Enter(_subscribeLock);
            if (_unsubscribe)
            {
                _unsubscribe = false;
                Monitor.Exit(_subscribeLock);
                Subscribe(false);
            }
            else
            {
                Monitor.Exit(_subscribeLock);
            }
        }
Esempio n. 4
0
        protected override void DrawFrame(CanvasImageSource sender, CanvasDrawingSession args)
        {
            if (_bitmap == null || _animation == null || _unloaded)
            {
                return;
            }

            if (_flipped)
            {
                args.Transform = Matrix3x2.CreateScale(-1, 1, sender.Size.ToVector2() / 2);
            }

            double width  = _bitmap.Size.Width;
            double height = _bitmap.Size.Height;

            double ratioX = (double)sender.Size.Width / width;
            double ratioY = (double)sender.Size.Height / height;

            if (ratioX > ratioY)
            {
                width   = sender.Size.Width;
                height *= ratioX;
            }
            else
            {
                width *= ratioY;
                height = sender.Size.Height;
            }

            var y = (sender.Size.Height - height) / 2;
            var x = (sender.Size.Width - width) / 2;

            if (sender.Size.Width >= _logicalSize.Width || sender.Size.Height >= _logicalSize.Height)
            {
                args.DrawImage(_bitmap,
                               new Rect(x, y, width, height));
            }
            else
            {
                args.DrawImage(_bitmap,
                               new Rect(x, y, width, height),
                               new Rect(0, 0, _bitmap.Size.Width, _bitmap.Size.Height), 1,
                               CanvasImageInterpolation.MultiSampleLinear);
            }

            if (_hideThumbnail == true)
            {
                _hideThumbnail = false;

                FirstFrameRendered?.Invoke(this, EventArgs.Empty);
                ElementCompositionPreview.SetElementChildVisual(this, null);
            }
        }
Esempio n. 5
0
        protected override void DrawFrame(CanvasImageSource sender, CanvasDrawingSession args)
        {
            var width  = (double)_animation.PixelWidth;
            var height = (double)_animation.PixelHeight;

            if (_stretch == Stretch.UniformToFill)
            {
                double ratioX = (double)sender.Size.Width / width;
                double ratioY = (double)sender.Size.Height / height;

                if (ratioX > ratioY)
                {
                    width   = sender.Size.Width;
                    height *= ratioX;
                }
                else
                {
                    width *= ratioY;
                    height = sender.Size.Height;
                }
            }
            else if (_stretch == Stretch.Uniform)
            {
                double ratioX = (double)sender.Size.Width / width;
                double ratioY = (double)sender.Size.Height / height;

                if (ratioX <= ratioY)
                {
                    width   = sender.Size.Width;
                    height *= ratioX;
                }
                else
                {
                    width *= ratioY;
                    height = sender.Size.Height;
                }
            }

            var y = (sender.Size.Height - height) / 2;
            var x = (sender.Size.Width - width) / 2;

            if (width >= _bitmap.Size.Width || height >= _bitmap.Size.Height)
            {
                args.DrawImage(_bitmap,
                               new Rect(x, y, width, height));
            }
            else
            {
                args.DrawImage(_bitmap,
                               new Rect(x, y, width, height),
                               new Rect(0, 0, _bitmap.Size.Width, _bitmap.Size.Height), 1,
                               CanvasImageInterpolation.MultiSampleLinear);
            }

            if (_prevSeconds != _nextSeconds)
            {
                _prevSeconds = _nextSeconds;
                PositionChanged?.Invoke(this, _nextSeconds);
            }

            if (_hideThumbnail == true && _thumbnail != null)
            {
                _hideThumbnail     = false;
                _thumbnail.Opacity = 0;

                FirstFrameRendered?.Invoke(this, EventArgs.Empty);
                ElementCompositionPreview.SetElementChildVisual(this, null);
            }
        }