Android - ImageView Mostrando la imagen de la galería en "paisaje"
Pregunta
Primero en absoluto, tal vez "paisaje" no es la mejor palabra para describir, pero no puedo pensar en otro en el momento.
Estoy usando el siguiente código para mostrar una imagen en una imagen Vista, pero mi imagen que se tomó con el dispositivo en "Retrato" (Head Up) se muestra a Sidelong.
Mi código:
mImageView = (ImageView) findViewById(R.id.iv_photo);
Uri u = Uri.parse("content://media/external/images/media/7");
mImageView.setImageURI(u);
xml:
<ImageView
android:id="@+id/iv_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
y sí, "Contenido: // medios / externos / imágenes / medios / 7" es una ruta válida.
¿Alguna idea?
Solución
Just check the image's dimensions, if it's taller than it is wider, then you can rotate it:
http://android-er.blogspot.com/2010/07/rotate-bitmap-image-using-matrix.html
The relevant bits are:
bitmap = BitmapFactory.decodeFile(imageInSD);
bmpWidth = bitmap.getWidth();
bmpHeight = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.postScale(curScale, curScale);
matrix.postRotate(curRotate);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true);
myImageView.setImageBitmap(resizedBitmap);
Otros consejos
android:id="@+id/iv_photo"
android:layout_width="320dip"
android:layout_height="wrap_content"/>
Use this it may works
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow