【问题标题】:How to save/export a lottie animation as a video file如何将乐天动画保存/导出为视频文件
【发布时间】:2020-03-15 18:54:39
【问题描述】:

我想将 Lottie 动画保存为视频(mp4 或任何其他视频格式)。

这是我尝试过的列表:

我真的知道如何在 Lottie 的 SurfaceView 中绘制每一帧

public class MyLottieAnimationView extends LottieAnimationView {
SurfaceHolder holder;

public void setHolder(SurfaceHolder holder) {
    this.holder = holder;
}

public MyLottieAnimationView(Context context) {
    super(context);
}

public MyLottieAnimationView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public MyLottieAnimationView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@Override
protected void onDraw(Canvas canvas) {

    Canvas c = holder.lockCanvas();
    if (c == null) {
        Log.e(TAG, "Cannot draw onto the canvas as it's null");
    } else {
        Bitmap myBitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.RGB_565);
        canvas.setBitmap(myBitmap);

        c.drawBitmap(myBitmap, 0, 0, new Paint());
//            c.
//            drawMyStuff(canvas);
        holder.unlockCanvasAndPost(canvas);
    }

    super.onDraw(canvas);
}

}

【问题讨论】:

标签: android video lottie


【解决方案1】:
val lottieComposition = LottieCompositionFactory.fromRawResSync(this, R.raw.android_wave) // your lottie json file 
    val lottieDrawable = LottieDrawable()
    lottieDrawable.composition = lottieComposition.value




val path = getExternalFilesDir(Environment.DIRECTORY_PICTURES) ?: File(cacheDir, Environment.DIRECTORY_PICTURES).apply { mkdirs() }
    val videoFile = File(path, "lottie_in_video.mp4")
    val recordingOperation = RecordingOperation(Recorder(videoOutput = videoFile), FrameCreator(lottieDrawable))
    {
      textView.text = getString(R.string.recording_finished)
      openCreatedVideo(videoFile)
    }

然后调用保存按钮

recordingOperation.start()

参考:https://github.com/rogererill/LottieRecorderTest

【讨论】:

  • 录制视频的每一帧会不会很费时间?
猜你喜欢
  • 2019-04-23
  • 1970-01-01
  • 2017-08-04
  • 2021-04-25
  • 1970-01-01
  • 2019-05-09
  • 2016-04-23
  • 2019-04-13
  • 2011-03-24
相关资源
最近更新 更多