Cómo redimensionar un mapa de bits eficientemente y sin perder calidad en android

Tengo un Bitmap con un tamaño de 320x480 y tengo que estirarlo en diferentes pantallas de dispositivo, he intentado usar esto:

 Rect dstRect = new Rect(); canvas.getClipBounds(dstRect); canvas.drawBitmap(frameBuffer, null, dstRect, null); 

funciona, la imagen llena toda la pantalla como quería pero la imagen está pixelada y se ve mal. Entonces lo intenté:

 float scaleWidth = (float) newWidth / width; float scaleHeight = (float) newHeight / height; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap resizedBitmap = Bitmap.createBitmap(frameBuffer, 0, 0, width, height, matrix, true); canvas.drawBitmap(resizedBitmap, 0, 0, null); 

esta vez se ve perfecto, agradable y suave, pero este código tiene que estar en mi bucle de juego principal y la creación de Bitmap s cada iteración lo hace muy lento. ¿Cómo puedo cambiar el tamaño de mi imagen para que no se pixelado y se hace rápido?

ENCONTRADO LA SOLUCIÓN:

 Paint paint = new Paint(); paint.setFilterBitmap(); canvas.drawBitmap(bitmap, matrix, paint); 

Cambiar el tamaño de un mapa de bits:

 public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) { int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // create a matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // recreate the new Bitmap Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false); return resizedBitmap; } 

Bastante autoexplicativo: simplemente ingrese el objeto Bitmap original y las dimensiones deseadas del Bitmap, y este método le devolverá el mapa de bits recién redimensionado. Puede ser, es útil para usted.

Estoy utilizando la solución anterior para cambiar el tamaño del mapa de bits. Pero la parte de los resultados de la imagen se pierde.

Aquí está mi código.

  BitmapFactory.Options bmFactoryOptions = new BitmapFactory.Options(); bmFactoryOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; bmFactoryOptions.inMutable = true; bmFactoryOptions.inSampleSize = 2; Bitmap originalCameraBitmap = BitmapFactory.decodeByteArray(pData, 0, pData.length, bmFactoryOptions); rotatedBitmap = getResizedBitmap(originalCameraBitmap, cameraPreviewLayout.getHeight(), cameraPreviewLayout.getWidth() - preSizePriviewHight(), (int) rotationDegrees); public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight, int angle) { int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; Matrix matrix = new Matrix(); matrix.postRotate(angle); matrix.postScale(scaleWidth, scaleHeight); Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); DeliverItApplication.getInstance().setImageCaptured(true); return resizedBitmap; } 

Tamaño de la superficie de vista previa: 352: 288 Anchura de mapa de bits antes de cambiar el tamaño: 320 Altura: 240 Anchura de la vista de la cámara: 1080 Altura: 1362 Anchura de mapa de bits con reajuste: 1022 Altura: 1307

  • Android - nuevo BitmapDrawable obsoleto; Alternativa Bitmap.createBitmap tiene que tener w / h> 0
  • Impresión POS / ESC Apex3 image SOS
  • Se produjo un error en la transacción del encuadernador al colocar un mapa de bits dinámicamente en un widget.
  • Bitmap escalado que mantiene la proporción de aspecto
  • MAT (Eclipse Memory Analyzer) - cómo ver los mapas de bits del volcado de memoria
  • Envío de imagen por correo electrónico, Android?
  • Android rotar mapa de bits sin hacer una copia
  • Android: error de "intentar utilizar un mapa de bits reciclado" con Bitmaps temporales
  • Cómo asignar una imagen (mapa de bits) mediante programación a un contacto?
  • Extraer mapa de bits del vídeo en android
  • mapa de bits de Android - mejores prácticas
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.