为了确保不OOM通常我们会对图片进行优化处理,让图片失真 这段代码运用了数据流来对图片进行优化 大家可以试试 很不错的呦
public class BitmapsUntils {
public static Bitmap loadBMP(Context context, String filename) {
Bitmap tmpBitmap = null;
AssetManager am = context.getAssets();
InputStream is = null;
try {
is = am.open(filename);
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
tmpBitmap = BitmapFactory.decodeStream(is, null, opt);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return tmpBitmap;
}
} |
|