【发布时间】:2020-03-15 18:54:39
【问题描述】:
我想将 Lottie 动画保存为视频(mp4 或任何其他视频格式)。
这是我尝试过的列表:
- How to save Lottie Animation as Video (.mp4) and GIF (.gif) in Android?
- 我试过这个Lottie Recorder Test lib。但我仍然收到issue with this lib also
- 有人告诉我record surfaceview using this lib。但是How to draw each frame of lottie onto the canvas?
我真的知道如何在 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);
}
}
【问题讨论】: