azchohfi / LottieUWP

UWP port of Lottie(https://github.com/airbnb/lottie-android)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It lost something when I using Win2d render

HHChaos opened this issue · comments

hi, I am using LottieUWP to develop a new uwp application, and I added a new method in your LottieDrawable class,so it can be rendered by win2d CanvasRenderTarget,but it doesnt work well,it lost something(for the following example its eyes).

I create a repository for display the problem:
https://github.com/HHChaos/LottieUwpTest

Added method in LottieDrawable.cs###

public CanvasCommandList GetCanvasImage(ICanvasResourceCreator resourceCreator, float scaleX, float scaleY)
    {
        lock (this)
        {
            var commandList = new CanvasCommandList(resourceCreator);
            using (var session = commandList.CreateDrawingSession())
            {
                var width = _composition.Bounds.Width * scaleX;
                var height = _composition.Bounds.Height * scaleY;
                if (_bitmapCanvas == null || _bitmapCanvas.Width < width || _bitmapCanvas.Height < height)
                {
                    _bitmapCanvas?.Dispose();
                    _bitmapCanvas = new BitmapCanvas(width, height);
                }

                using (_bitmapCanvas.CreateSession(resourceCreator.Device, (float) width,
                    (float) height, session))
                {
                    _bitmapCanvas.Clear(Colors.Transparent);
                    LottieLog.BeginSection("Drawable.Draw");
                    if (_compositionLayer == null)
                    {
                        return null;
                    }

                    _matrix.Reset();
                    _matrix = MatrixExt.PreScale(_matrix, scaleX, scaleY);
                    _compositionLayer.Draw(_bitmapCanvas, _matrix, _alpha);
                    LottieLog.EndSection("Drawable.Draw");
                }

            }

            return commandList;
        }
    }

Hi @azchohfi , HHChaos is my teammate and we are developing the 'Letsdraw' UWP App, Which used Win2D to render hand-drawing and 2d animation. And in this version we added support for Lottie element, so we tried to use LottieUWP and Win2D to render it, but it doesn't work well in HHChaos' issue. So please help us to check if there are some issues in our code, or should we use this method to render it with LottieUWP and Win2D, Thanks!

@azchohfi
This problem has been solved, you can closed this issue.
The bug appeared to be related to the CanvasCommandList infinite size, and when I replaced it with the CanvasRenderTarget, it work well!

Perfect! Thanks!