美文网首页
Android 读取本地资源图片

Android 读取本地资源图片

作者: mocen_王琪 | 来源:发表于2017-10-19 08:59 被阅读193次
以最节省内存的方式读取本地图片文件,生成Bitmap对象
    public static Bitmap readBitMap(Context context, int resId) {
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
        opt.inPurgeable = true;
        opt.inInputShareable = true;
        //获取资源图片
        InputStream is = context.getResources().openRawResource(resId);
        return BitmapFactory.decodeStream(is,null,opt);
    }

相关文章

网友评论

      本文标题:Android 读取本地资源图片

      本文链接:https://www.haomeiwen.com/subject/zboyuxtx.html