您的位置:首页 > 移动开发 > Android开发

Android—压缩图片,减少内存

2015-08-26 10:02 471 查看
    private BitmapDrawable setBimap(int resId){

    BitmapFactory.Options opt = new BitmapFactory.Options();

    opt.inPreferredConfig = Bitmap.Config.RGB_565;

    opt.inPurgeable = true;

    opt.inInputShareable = true;

    //获取资源图片

    InputStream is = HelpPagerFragment.this.getActivity().getResources().openRawResource(resId);

    Bitmap bitmap = BitmapFactory.decodeStream(is,null, opt);

    try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

    return new BitmapDrawable(mContext.getResources(),bitmap);
    }

使用

view = inflater.inflate(R.layout.helppage5, container, false);
view.setBackgroundDrawable(setBimap(R.drawable.helppage5));

原文地址:http://jingyan.baidu.com/article/ed2a5d1f3191d109f6be17e8.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  压缩图片