Ich habe eine, die funktioniert gut auf meinem Handy. Als ich jedoch die Live-Crash-Daten überprüft habe, erhalten die Leute den Fehler "Nicht genügend Arbeitsspeicher".Android bekommen java.lang.OutOfMemoryError beim Ändern der Bildgröße
java.lang.OutOfMemoryError
Ich versuche Bild von dem Foto zu laden und zu versuchen, das Bild kleiner zu machen.
Hier ist mein Code
Die RequiredSize ist 1000
public static Bitmap getImage(Context c, Uri uri, final int requiredSize)
throws FileNotFoundException {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(c.getContentResolver().openInputStream(uri), null, o);
int width_tmp = o.outWidth
, height_tmp = o.outHeight;
int scale = 1;
while(true) {
if(width_tmp/2 < requiredSize || height_tmp/2 < requiredSize)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(c.getContentResolver().openInputStream(uri), null, o2); //This is the line that's getting the error
}