Ich habe versucht, in meiner Anwendung Bild aus der Galerie zu bekommen und es in Image setzen, aber ich bekomme Fehler „OutOfMemoryError“In Image nicht zeigt Bild aus der Galerie
FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:623)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:695)
at kz.app.discount.activities.AddingProduct.onActivityResult(AddingProduct.java:374)
at android.app.Activity.dispatchActivityResult(Activity.java:5456)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3402)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3449)
at android.app.ActivityThread.access$1200(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1328)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)`
-Code von Galerie mit Absicht immer Bild. ACTION_PICK und onActivityResult():
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
Bitmap bitmap = null;
ImageView imageView = iVAddProductDiscountPicture;
switch (requestCode) {
case GALLERY_REQUEST:
if (resultCode == RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImage);
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 10, stream);
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(stream.toByteArray()));
//TODO: дописать код сжатия изображения
imageView.setImageBitmap(decoded);
} catch (IOException e) {
e.printStackTrace();
}
alertDialog.dismiss();
}
}
}
'OutOfMemoryError' bedeutet, dass das Bild zu groß ist von Ihrem Gerät behandelt werden. Laden Sie es bereits skaliert. –
@MichaelDodd, spielt die Dateigröße keine Rolle, nur die Auflösung. –
@Wladimir Rudnicky bitte erhöhen Sie die Bitmap-Komprimierungsgröße 10 auf 100 und versuchen Sie bitmap.compress (Bitmap.CompressFormat.JPEG, 100, stream); –