android– 播放动画gif作为电影只显示画布背景

android– 播放动画gif作为电影只显示画布背景,第1张

概述我想在我的Android应用程序中播放动画gif.我注意到WebView可以正常使用这段代码:webview.loadUrl("file:///android_asset/gif.gif");不幸的是,webView太占用内存,我的应用程序经常崩溃.我看过很多像这样使用Movie的教程:publicclassGIFViewextendsView{privateMo

我想在我的Android应用程序中播放动画gif.

我注意到WebVIEw可以正常使用这段代码:

webvIEw.loadUrl("file:///androID_asset/gif.gif");

不幸的是,webVIEw太占用内存,我的应用程序经常崩溃.

我看过很多像这样使用MovIE的教程:

public class GIFVIEw extends VIEw {    private MovIE movIE;    private long movIEstart;    public GIFVIEw(Context context) throws IOException {        super(context);        movIE = MovIE.decodeStream(getResources().getAssets().open("gif.gif"));    }    public GIFVIEw(Context context, AttributeSet attrs) throws IOException {        super(context, attrs);        movIE = MovIE.decodeStream(getResources().getAssets().open("gif.gif"));    }    public GIFVIEw(Context context, AttributeSet attrs, int defStyle)            throws IOException {        super(context, attrs, defStyle);        movIE = MovIE.decodeStream(getResources().getAssets().open("gif.gif"));    }    private long _start_time;    @OverrIDe    protected voID onDraw(Canvas canvas) {        canvas.drawcolor(color.RED);        super.onDraw(canvas);        long _current_time = androID.os.SystemClock.uptimeMillis();        if (0 == _start_time) {            _start_time = _current_time;        }        if (null != movIE) {            final int _relatif_time = (int) ((_current_time - _start_time) % movIE                    .duration());            movIE.setTime(_relatif_time);            Log.i("",""+_relatif_time);            double scalex = (double) this.getWIDth() / (double) movIE.wIDth();            double scaley = (double) this.getHeight() / (double) movIE.height();            canvas.scale((float) scalex, (float) scaley);             movIE.draw(canvas, (float) scalex, (float) scaley)        }        this.invalIDate();    }}

当我得到一个大的红色窗口时,我可以看到Canvas被绘制,并且我添加了Log,我可以看到我的电影不是null并且有一个长度!

不幸的是,除了大红色矩形之外,画布上没有任何内容,我已经使用不同的gif文件进行了测试.

知道为什么这不起作用吗?

解决方法:

您可以查看我的库源代码https://github.com/sbakhtiarov/gif-movie-view,我们只需使用它.

总结

以上是内存溢出为你收集整理的android – 播放动画gif作为电影只显示画布背景全部内容,希望文章能够帮你解决android – 播放动画gif作为电影只显示画布背景所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1113155.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存