与GIF图像工作 [英] Working with Gif Image

查看:129
本文介绍了与GIF图像工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在Android中使用的Gif 图像的任何地方?我用一个例子这种类型的图像。这表明只喜欢不动。

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

我们怎样才能为GIF(可移动)图像使用?这是可能在Android中?

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

任何人指导我?

推荐答案

我打得GIF图像这样的...

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();
        }
    }
}

这篇关于与GIF图像工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆