0
我的xml文件中有很多位圖,並且出現內存不足異常。如何在添加到xml文件之前調整圖像
我有這段代碼來調整位圖大小來減少空間。
public static Bitmap decodeSampledBitmapFromResource(Resources res,
int resId, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
我如何可以使用此代碼來調整圖像在我繪製文件夾之前它們在XML文件中,所以我不出現內存不足的例外的加入?