使用 Gif 图像

发布于 2024-12-18 14:40:38 字数 216 浏览 1 评论 0原文

我们可以在android中的任何地方使用Gif图像吗?我使用了此类图像的一个示例。它仅显示为不可移动。

我们如何使用 Gif(可移动)图像?这在 Android 中可能吗?

有人指导我吗?

Can we use Gif image in android anywhere? I've used one example for this type of image. It shows like immovable only.

How can we use as Gif(movable) image? Is this possible in Android?

Anyone guide me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何其悲哀 2024-12-25 14:40:38

我像这样播放gif图像...

public class GIFDemo extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new GIFView(this));
    }
    private static class GIFView extends View{

        Movie movie,movie1;
        InputStream is=null,is1=null;
        long moviestart;
        long moviestart1;
        public GIFView(Context context) {
            super(context);
            is=context.getResources().openRawResource(R.drawable.cartoon);
            is1=context.getResources().openRawResource(R.drawable.animated_gif);
            movie=Movie.decodeStream(is);
            movie1=Movie.decodeStream(is1);
            //BitmapFactory.Options opts = new BitmapFactory.Options();
            //opts.inJustDecodeBounds = true;    // this will request the bm
           // opts.inSampleSize = 10;   
            //movie=Movie.decodeFile("C:\\cartoon.gif");
        }

        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawColor(0xFFCCCCCC);
            super.onDraw(canvas);
            long now=android.os.SystemClock.uptimeMillis();
            System.out.println("now="+now);
             if (moviestart == 0) {   // first time
                 moviestart = now;

             }
             if(moviestart1==0)
             {
                 moviestart1=now;
             }
             System.out.println("\tmoviestart="+moviestart);
             int relTime = (int)((now - moviestart) % movie.duration()) ;
             int relTime1=(int)((now - moviestart1)% movie1.duration());
             System.out.println("time="+relTime+"\treltime="+movie.duration());
             movie.setTime(relTime);
             movie1.setTime(relTime1);
             movie.draw(canvas,10,10);
             movie1.draw(canvas,10,100);
             this.invalidate();
        }
    }
}

I played gif image like this...

public class GIFDemo extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new GIFView(this));
    }
    private static class GIFView extends View{

        Movie movie,movie1;
        InputStream is=null,is1=null;
        long moviestart;
        long moviestart1;
        public GIFView(Context context) {
            super(context);
            is=context.getResources().openRawResource(R.drawable.cartoon);
            is1=context.getResources().openRawResource(R.drawable.animated_gif);
            movie=Movie.decodeStream(is);
            movie1=Movie.decodeStream(is1);
            //BitmapFactory.Options opts = new BitmapFactory.Options();
            //opts.inJustDecodeBounds = true;    // this will request the bm
           // opts.inSampleSize = 10;   
            //movie=Movie.decodeFile("C:\\cartoon.gif");
        }

        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawColor(0xFFCCCCCC);
            super.onDraw(canvas);
            long now=android.os.SystemClock.uptimeMillis();
            System.out.println("now="+now);
             if (moviestart == 0) {   // first time
                 moviestart = now;

             }
             if(moviestart1==0)
             {
                 moviestart1=now;
             }
             System.out.println("\tmoviestart="+moviestart);
             int relTime = (int)((now - moviestart) % movie.duration()) ;
             int relTime1=(int)((now - moviestart1)% movie1.duration());
             System.out.println("time="+relTime+"\treltime="+movie.duration());
             movie.setTime(relTime);
             movie1.setTime(relTime1);
             movie.draw(canvas,10,10);
             movie1.draw(canvas,10,100);
             this.invalidate();
        }
    }
}
箜明 2024-12-25 14:40:38

请查看这篇文章。我认为这对你有帮助
有关 gif 动画的更多信息,请参阅此问题

Take a look at this article. I think it helps you
And for more info about gif animation look at this question

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文