示例#1
0
 private void ClearComposition()
 {
     RecycleBitmaps();
     _compositionLayer  = null;
     _imageAssetManager = null;
     InvalidateSelf();
 }
        private static void Draw(CanvasDevice device, BitmapCanvas bitmapCanvas, CompositionLayer compositionLayer, Rect bounds, float scale, byte alpha, Matrix3X3 matrix, double width, double height, CanvasDrawingSession canvasDrawingSession)
        {
            using (bitmapCanvas.CreateSession(device, width, height, canvasDrawingSession))
            {
                bitmapCanvas.Clear(Colors.Transparent);
                LottieLog.BeginSection("Drawable.Draw");
                if (compositionLayer == null)
                {
                    return;
                }

                var   localScale = scale;
                float extraScale = 1f;

                float maxScale = GetMaxScale(bitmapCanvas, bounds);
                if (localScale > maxScale)
                {
                    localScale = maxScale;
                    extraScale = scale / localScale;
                }

                if (extraScale > 1)
                {
                    // This is a bit tricky...
                    // We can't draw on a canvas larger than ViewConfiguration.get(context).getScaledMaximumDrawingCacheSize()
                    // which works out to be roughly the size of the screen because Android can't generate a
                    // bitmap large enough to render to.
                    // As a result, we cap the scale such that it will never be wider/taller than the screen
                    // and then only render in the top left corner of the canvas. We then use extraScale
                    // to scale up the rest of the scale. However, since we rendered the animation to the top
                    // left corner, we need to scale up and translate the canvas to zoom in on the top left
                    // corner.
                    bitmapCanvas.Save();
                    float halfWidth        = (float)bounds.Width / 2f;
                    float halfHeight       = (float)bounds.Height / 2f;
                    float scaledHalfWidth  = halfWidth * localScale;
                    float scaledHalfHeight = halfHeight * localScale;
                    bitmapCanvas.Translate(
                        scale * halfWidth - scaledHalfWidth,
                        scale * halfHeight - scaledHalfHeight);
                    bitmapCanvas.Scale(extraScale, extraScale, scaledHalfWidth, scaledHalfHeight);
                }

                matrix.Reset();
                matrix = MatrixExt.PreScale(matrix, localScale, localScale);
                compositionLayer.Draw(bitmapCanvas, matrix, alpha);
                LottieLog.EndSection("Drawable.Draw");

                if (extraScale > 1)
                {
                    bitmapCanvas.Restore();
                }
            }
        }
示例#3
0
 public void ClearComposition()
 {
     RecycleBitmaps();
     if (_animator.IsRunning)
     {
         _animator.Cancel();
     }
     _composition       = null;
     _compositionLayer  = null;
     _imageAssetManager = null;
     InvalidateSelf();
 }
示例#4
0
 private void BuildCompositionLayer()
 {
     _compositionLayer = new CompositionLayer(this, LayerParser.Parse(_composition), _composition.Layers, _composition);
 }
示例#5
0
 private void BuildCompositionLayer()
 {
     _compositionLayer = new CompositionLayer(this, Layer.Factory.NewInstance(_composition), _composition.Layers, _composition);
 }