码迷,mamicode.com
首页 > 其他好文 > 详细

关于在帧动画 的动态加载

时间:2016-09-13 19:09:42      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

加载本地缓存图片

 

List<String> imgList = new ArrayList<String>();

        imgList.add("本地图片地址");
      imgList.add("本地图片地址");
        for (int i = 0; i < imgList.size(); i++) {
//路径地址变转变成 //Drawable
            Drawable drawable = getDrawable(imgList.get(i));
            if (drawable != null) {
//添加到动画对象中
                anim.addFrame(drawable, 200);
            }
        }
        anim.setOneShot(false);
        imageView.setImageDrawable(anim);
        anim.start();

  工具类

 

    public Drawable getDrawable(String filePath) {
        Bitmap bitmap = readBitMap(filePath);
        if (bitmap != null) {
            BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
            return bitmapDrawable;
        }
        return null;
    }


    public static Bitmap readBitMap(String filePath) {
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
        opt.inPurgeable = true;
        opt.inInputShareable = true;
        return decodeBmp(filePath, opt);
    }

    public static Bitmap decodeBmp(String imgPath, BitmapFactory.Options opts) {
        Bitmap dstBmp = null;
        FileInputStream fis;
        try {
            fis = new FileInputStream(imgPath);
            dstBmp = BitmapFactory.decodeStream(fis, null, opts);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (OutOfMemoryError e) {
            opts.inSampleSize += 1;
            opts.inPreferredConfig = Bitmap.Config.RGB_565;
            opts.inPurgeable = true;
            opts.inInputShareable = true;
            opts.inJustDecodeBounds = false;
            dstBmp = decodeBmp(imgPath, opts);
        }
        return dstBmp;
    }

  

关于在帧动画 的动态加载

标签:

原文地址:http://www.cnblogs.com/TomCzr/p/5869303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!