MediaStore.Images.Media.getBitmap y fuera de error de memoria

Mi código de código es:

public Bitmap loadPhoto(Uri uri) { Bitmap scaled = null; try { scalled = Bitmap.createBitmap( MediaStore.Images.Media.getBitmap(getContentResolver(), uri), 0,0,90, 90); if (scaled == null) { return null; } } catch(Exception e) { } return scaled; } 

Después de este. Muestra escala en ImageView. Cada imagen viene de la cámara del dispositivo.

Cada vez, consigo el error: fuera de memoria después de que exhibo tres fotos de la cámara fotográfica. ¿Cómo resolver esto?

Intente utilizar BitmapFactory para solucionar el problema http://developer.android.com/reference/android/graphics/BitmapFactory.html

Para aquellos que buscan muestra de código:

 private static int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { final int halfHeight = height / 2; final int halfWidth = width / 2; // Calculate the largest inSampleSize value that is a power of 2 and keeps both // height and width larger than the requested height and width. while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) { inSampleSize *= 2; } } return inSampleSize; } public static Bitmap decodeSampledBitmapFromUri(Context context, Uri imageUri, int reqWidth, int reqHeight) throws FileNotFoundException { // Get input stream of the image final BitmapFactory.Options options = new BitmapFactory.Options(); InputStream iStream = context.getContentResolver().openInputStream(imageUri); // First decode with inJustDecodeBounds=true to check dimensions options.inJustDecodeBounds = true; BitmapFactory.decodeStream(iStream, null, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeStream(iStream, null, options); } 

El método MediaStore.getBitmap es un método de conveniencia que no especifica un tamaño de muestra al obtener el mapa de bits. Si está utilizando getBitmap (ContentResolver, Uri) y desea utilizar un tamaño de muestra, use ContentResolver para obtener el flujo de entrada y descodifique el mapa de bits como lo haría normalmente (calculando el tamaño de la muestra primero y luego cargando el tamaño de la muestra).

  • Cargar imagen de url en la notificación de Android
  • Cómo obtener el mapa de bits que proporciona un URI, java.io.FileNotFoundException: No hay proveedor de contenido: /sdcard/Hello/1310610722879.jpg
  • Idioma (s) / Marco adecuado para mapa móvil interactivo
  • Cómo centrar el texto en android IconGenerator
  • Android código de bits de código nativo - problema de enlace
  • Android convertir vista XML a mapa de bits sin mostrarlo
  • Osmdroid: ¿Cómo puedo crear y cargar un mapa de mis propios mapas de bits (mosaicos)?
  • Mi papel de mapa de bits desplazable es demasiado lento para usar
  • Android - BitmapFactory.decodeByteArray - OutOfMemoryError (OOM)
  • Convertir la imagen de recursos desplegables en mapa de bits
  • Fábrica de mapas de bits de Android sin memoria Segunda foto
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.