Cómo obtener una imagen recortada de ImageView
Utilizo ImageView para recortar un mapa de bits. Una vez que se recorta quiero obtener esa imagen recortada, pero recibo lo mismo que el original. ¿Hay una manera de obtener sólo la parte visible de la imagen?
ImageView iv = new ImageView(this); iv.setImageBitmap(OriginalBitmap); iv.setScaleType(ScaleType.CENTER_CROP); Bitmap CroppedBitmap = ((BitmapDrawable) iv.getDrawable()).getBitmap();
El valor de CroppedBitmap es como el OriginalBitmap. ¿Cómo puedo obtener el recortado?
- ImageView ScaleType ignora el relleno
- Animación de desenfoque de Android ImageView
- Múltiples animaciones en 1 imageview android
- ImageView: relleno horizontal manteniendo relación de aspecto
- ImageView en el diseño de android XML con layout_height = "wrap_content" tiene relleno superior e inferior
- Extraño comportamiento de las imágenes en RecyclerView
- cómo enviar la imagen de una actividad a otra?
- ImageView en forma circular a través de xml
- Añadir texto a la imagen en android mediante programación
- Android: java.lang.OutOfMemoryError:
- Android: cargar archivo svg desde la web y mostrarlo en la vista de imagen
- Android, ImageView sobre ImageView
- Cambiar el tamaño de ImageView en tiempo de ejecución mediante un botón - Android
Este ejemplo funciona para mí iv.setDrawingCacheEnabled(true); Bitmap croppedBitmap = iv.getDrawingCache()
iv.setDrawingCacheEnabled(true); Bitmap croppedBitmap = iv.getDrawingCache()
Este código siguiente para recortar la imagen 200×200
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.android); int width = bitmapOrg.width(); int height = bitmapOrg.height(); int newWidth = 200; int newHeight = 200; // calculate the scale - in this case = 0.4f float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // createa matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // recreate the new Bitmap Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); // make a Drawable from Bitmap to allow to set the BitMap // to the ImageView, ImageButton or what ever BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); iv.setImageDrawable(bmd);
- Icono de la pestaña de cambio de Android
- Incorporación del protocolo XMPP a una aplicación de Android