在Android的Play.gif图像,而无需使用web视图 [英] Play.gif image in android without using webview
问题描述
我想是这样的,我发现在网络上播放GIF图像:
I tried like this, which i found on the net to play gif images:
private class MYGIFView extends View {
Movie movie;
InputStream is = null;
long moviestart;
public MYGIFView(Context context) {
super(context);
// Provide your own gif animation file
is = context.getResources().openRawResource(R.drawable.mygif);
movie = Movie.decodeStream(is);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);
super.onDraw(canvas);
long now = android.os.SystemClock.uptimeMillis();
System.out.println("now=" + now);
if (moviestart == 0) { // first time
moviestart = now;
}
System.out.println("\tmoviestart=" + moviestart);
int relTime = (int) ((now - moviestart) % movie.duration());
System.out.println("time=" + relTime + "\treltime="
+ movie.duration());
movie.setTime(relTime);
movie.draw(canvas, this.getWidth() / 2 - 20,
this.getHeight() / 2 - 40);
this.invalidate();
}
虽然很多人说,他们得到了他们想要的结果。
Though many have said that they got their desired result.
我已经把GIF图像的绘制。 我越来越movie.duration()返回null。
I have put the gif image in drawable. I am getting movie.duration() null.
请建议我在哪里错了,或者是有什么办法。
Please suggest where am i wrong or if is there any way.
推荐答案
没有的WebView
Android无法播放GIF文件。你必须仔细分解成框架,并自己制作动画。
Android cannot play GIF files without WebView
. You must break it apart into frames and animate it yourself.
我发现了另一个计算器后该位从XoyoSoft ,叫GifSplitter软件,能够分裂GIF格式为帧。这样,你会希望使用 AnimationDrawable
结合这些。
I found on another StackOverflow post this bit of software from XoyoSoft, called GifSplitter, that can split a GIF into frames. You would then want to use AnimationDrawable
to combine those.
这将是这个样子:
// Your files:
res\drawable-xxxx\frame1.jpg
res\drawable-xxxx\frame2.jpg
res\drawable-xxxx\frame3.jpg
// ...
res\drawable-xxxx\frame99.jpg
那么,有 AnimationDrawable
文档上面的例子将展示如何显示这些图像。
Then, there is an example in the AnimationDrawable
documentation above that will show how to display those images.
最后,你必须加载和播放动画;这也被详细介绍了 AnimationDrawable
文档。
Lastly, you must load and play the animation; that, too, is detailed in the AnimationDrawable
documentation.
这篇关于在Android的Play.gif图像,而无需使用web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!