Android - ImageView在"风景"中显示图库中的图像

Rai*_*ist 5 android landscape portrait image

首先,也许"风景"并不是更好的词语,但我现在想不到另一个.

我正在使用以下代码在ImageView中显示图像,但我在"肖像"(抬头)中使用设备拍摄的图像显示为侧面.

我的代码:

mImageView  = (ImageView) findViewById(R.id.iv_photo);

Uri u = Uri.parse("content://media/external/images/media/7");
mImageView.setImageURI(u);
Run Code Online (Sandbox Code Playgroud)

XML:

<ImageView
    android:id="@+id/iv_photo"
    android:layout_width="wrap_content"          
    android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)

是的,"content:// media/external/images/media/7"是一条有效路径.

有任何想法吗?

Joe*_*nez 3

只需检查图像的尺寸,如果它的高度大于宽度,那么您可以旋转它: http:
//android-er.blogspot.com/2010/07/rotate-bitmap-image-using-matrix.html

相关位是:

  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);
Run Code Online (Sandbox Code Playgroud)