根據我的要求,我有一個用於調整位圖圖像大小的簡單類。有負責它的簡單方法如下:位圖調整大小會導致內存不足
public static Bitmap ResizeRichImages(Bitmap bitmap, Context mContext){
try {
float originalBitmapWidth = bitmap.getWidth();
float originalBitmapHeight = bitmap.getHeight();
float originalAspectRatio = originalBitmapWidth/originalBitmapHeight;
double width_percentage = (0.05*screenWidthPixels(mContext));
float newWidth = (float)((int)screenWidthPixels(mContext)-width_percentage);
float newBitmapWidth = newWidth;
float newBitmapHeight = newBitmapWidth/originalAspectRatio;
bitmap = Bitmap.createScaledBitmap(bitmap, (int) newWidth, (int)newBitmapHeight, false);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
這是我如何調用此方法:
String URL = "https://maps.googleapis.com/maps/api/staticmap?center=-33.86527274921529,151.2050531328867&zoom=15&size=640x360&sensor=false&markers=color:blue%7Clabel:!%7C-33.86527274921529,151.2050531328867";
try {
bmp = Picasso.with(ViewStory.this).load(URL)
.get();
bmp = ImageController.ResizeRichImages(bmp, ViewStory.this);
} catch (Exception e) {
e.printStackTrace();
}
但是,幾乎每一個我收到了內存異常,同時調用時間ResizeRichImages方法。我哪裏錯了?
何去何從是screenWidthPixels(mContext) –
請檢查:http://stackoverflow.com/questions/26296344/out-of-memory-error-for-files-greater-than-3mb-though-upload-using-chunk/26296433#26296433 – pbespechnyi
''android:largeHeap「'只隱藏問題......非常普遍的**你不應該使用它** ...但它通常被糟糕的程序員使用(沒有知識和技能)和noobs – Selvin