Creación de un mapa de bits escalado con createScaledBitmap en Android

Quiero crear un mapa de bits a escala, pero aparentemente obtener una imagen desproporcional. Parece un cuadrado mientras que quiero ser rectangular.

Mi código:

Bitmap resizedBitmap = Bitmap.createScaledBitmap(myBitmap, 960, 960, false); 

Quiero que la imagen tenga un MAX de 960. ¿Cómo haría eso? El ancho de configuración a null no se compila. Es probablemente simple, pero no puedo envolver mi cabeza alrededor de él. Gracias

Si ya tiene el mapa de bits original en la memoria, no necesita hacer todo el proceso de inJustDecodeBounds , inSampleSize , etc. Sólo tiene que averiguar qué proporción utilizar y escalar en consecuencia.

 final int maxSize = 960; int outWidth; int outHeight; int inWidth = myBitmap.getWidth(); int inHeight = myBitmap.getHeight(); if(inWidth > inHeight){ outWidth = maxSize; outHeight = (inHeight * maxSize) / inWidth; } else { outHeight = maxSize; outWidth = (inWidth * maxSize) / inHeight; } Bitmap resizedBitmap = Bitmap.createScaledBitmap(myBitmap, outWidth, outHeight, false); 

Si el único uso para esta imagen es una versión escalada, es mejor utilizar la respuesta de Tobiel, para minimizar el uso de memoria.

Tu imagen es cuadrada porque estás estableciendo width = 960 y height = 960 .

Usted necesita crear un método donde usted pasa el tamaño de la imagen que usted quiere como esto: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

En código se ve así:

 public static Bitmap lessResolution (String filePath, int width, int height) { int reqHeight = height; int reqWidth = width; BitmapFactory.Options options = new BitmapFactory.Options(); // First decode with inJustDecodeBounds=true to check dimensions options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filePath, options); } private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { // Calculate ratios of height and width to requested height and width final int heightRatio = Math.round((float) height / (float) reqHeight); final int widthRatio = Math.round((float) width / (float) reqWidth); // Choose the smallest ratio as inSampleSize value, this will guarantee // a final image with both dimensions larger than or equal to the // requested height and width. inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; } return inSampleSize; } 
 bmpimg = Bitmap.createScaledBitmap(srcimg, 100, 50, true); 
  • Crear dibujable desde mapa de bits
  • ¿Error de "Tratar de usar bitmap reciclado" de Android?
  • Ronda de las esquinas inferior en Android Bitmap?
  • Android: mapa de bits de una vista de gran tamaño
  • Problemas de calidad al cambiar el tamaño de una imagen en tiempo de ejecución
  • Obtenga el ancho y la altura del mapa de bits sin cargar en la memoria
  • Java.lang.OutOfMemoryError - BitmapFactory.decode (strPath)
  • Cómo dibujar un mapa de bits en Android con OpenGL
  • Cómo recortar mapa de bits con una ruta de acceso
  • Android: Cómo utilizar grantUriPermission para poder crear y enviar un correo electrónico con un archivo adjunto de mapa de bits
  • Combinar imágenes en android
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.