关于在帧动画 的动态加载

加载本地缓存图片

 

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

  

转载于:https://www.cnblogs.com/TomCzr/p/5869303.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值