Android—压缩图片,减少内存

来源:互联网 发布:指向数组元素的指针 编辑:程序博客网 时间:2024/05/16 05:11
    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

0 0
原创粉丝点击