【问题标题】:Working with Gif Image使用 Gif 图像
【发布时间】:2011-11-30 14:06:27
【问题描述】:

我们可以在任何地方在android中使用Gif图像吗?我已经为这种类型的图像使用了一个示例。它只显示不动。

我们如何使用 Gif(movable) 图像?这在 Android 中可行吗?

有人指导我吗?

【问题讨论】:

    标签: android image gif


    【解决方案1】:

    我是这样播放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();
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      看看this的文章。我觉得对你有帮助
      有关 gif 动画的更多信息,请查看question

      【讨论】:

        猜你喜欢
        • 2020-08-30
        • 2015-11-21
        • 1970-01-01
        • 2011-06-17
        • 1970-01-01
        • 1970-01-01
        • 2013-12-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多