5

首先,也许“风景”不是更好的形容词,但我现在想不出另一个。

我正在使用以下代码在 ImageView 中显示图像,但我使用设备在“纵向”(抬头)中拍摄的图像显示为侧向显示。

我的代码:

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

是的,“content://media/external/images/media/7”是一个有效的路径。

有任何想法吗?

4

2 回答 2

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);
于 2012-01-26T18:59:20.557 回答
0

android:id="@+id/iv_photo"

android:layout_width="320dip"   

android:layout_height="wrap_content"/>

使用它可能有效

于 2012-05-02T05:42:46.180 回答