我目前正在开发一款Android应用,可将普通的gif文件转换为视频。但经过一些研究后,我没有找到任何好的例子或提示。我见过一些现有的应用程序,它们具有这种功能,所以我确信有一种方法,但在我看来,大多数应用程序都是不一致的和错误的。有没有人有一个例子,它是如何完成的?
此致 马克
答案 0 :(得分:0)
class ACT_GIF_MOV extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setView();
}
void setView()
{
InputStream stream = null;
try {
stream = getAssets().open("animation.gif");
}
catch (IOException e)
{
e.printStackTrace();
}
GifMovieView view = new GifMovieView(this, stream);
setContentView(view);
}
class GifMovieView extends View
{
private Movie mMovie;
InputStream mStream;
long mMoviestart=0;
public GifMovieView(Context context, InputStream stream)
{
super(context);
mStream = stream;
mMovie = Movie.decodeStream(mStream);
}
@Override protected void onDraw(Canvas canvas)
{
canvas.drawColor(Color.TRANSPARENT);
super.onDraw(canvas);
final long now = SystemClock.uptimeMillis();
if (mMoviestart == 0) { mMoviestart = now; }
final int relTime = (int)((now - mMoviestart) % mMovie.duration()); mMovie.setTime(relTime);
mMovie.draw(canvas, 10, 10); this.invalidate();
}
}
}