5

First at all, maybe "landscape" isn't the better word to describe, but i can't think another one in the moment.

I'm using the following code to show an image in an ImageView, but my image that was taken with the device in "portrait" (head up) is showing sidelong.

My code:

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

And yes, "content://media/external/images/media/7" is a valid path.

Any ideas?

Raist
  • 99
  • 2
  • 7
  • Yes. Turns out that my device only take pictures in landscape. The "bug" was between chair and keyboard. :( – Raist Aug 22 '12 at 13:31

2 Answers2

3

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);
Joel Martinez
  • 46,929
  • 26
  • 130
  • 185
0

android:id="@+id/iv_photo"

android:layout_width="320dip"   

android:layout_height="wrap_content"/>

Use this it may works

Umer Abid
  • 397
  • 1
  • 14