Domanda

Prima del tutto, forse "Paesaggio" non è la parola migliore da descrivere, ma non riesco a pensarne un altro nel momento.

Sto usando il seguente codice per mostrare un'immagine in un imageview, ma la mia immagine scattata con il dispositivo in "ritratto" (la testa in alto) sta mostrando sidelong.

Il mio codice:

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"/>
.

E Sì, "Contenuto: // Media / Esterno / Immagini / Media / 7" è un percorso valido.

Qualche idea?

È stato utile?

Soluzione

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);

Altri suggerimenti

android:id="@+id/iv_photo"

android:layout_width="320dip"   

android:layout_height="wrap_content"/>

Use this it may works

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top