【发布时间】:2015-08-28 11:04:45
【问题描述】:
我有一个简单的类,用于根据我的要求调整位图图像的大小。有一个简单的方法负责它:
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)
-
"android:largeHeap"只是隐藏问题...通常你不应该使用它 ...但它通常被糟糕的程序员使用(没有知识和技能)和菜鸟 -
...还有...毕加索有它自己的resize方法...你为什么不使用它
标签: java android bitmap out-of-memory