解决 out of memory 的方法

来源:互联网 发布:php在线教学平台源码 编辑:程序博客网 时间:2024/06/08 16:56
private Bitmap decodeBitmap(File file){        try{            BitmapFactory.Options o = new BitmapFactory.Options();            o.inJustDecodeBounds = true;            BitmapFactory.decodeStream(new FileInputStream(file),null,o);            Bitmap currentBitmap = Bitmap.createBitmap(o.outWidth,o.outHeight, Bitmap.Config.ARGB_8888);            final int REQYIRED_SIZE  = 800;            int scale = 1;            while (o.outWidth / 2 / scale >= REQYIRED_SIZE && o.outHeight / 2 /scale >= REQYIRED_SIZE){                scale *= 2;            }            //Log.e(TAG, "decodeBitmap: scale---"+scale);            o.inJustDecodeBounds = false;            o.inSampleSize = scale;            o.inMutable = true;            o.inBitmap = currentBitmap;            return BitmapFactory.decodeStream(new FileInputStream(file),null,o);            //return currentBitmap;        }catch (Exception e){            e.printStackTrace();        }        return null;    }

0 0
原创粉丝点击