簡體   English   中英

Android - ImageView在“風景”中顯示圖庫中的圖像

[英]Android - ImageView showing image from Gallery in “landscape”

首先,也許“風景”並不是更好的詞語,但我現在想不到另一個。

我正在使用以下代碼在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”是一條有效路徑。

有任何想法嗎?

只需檢查圖像的尺寸,如果它比它更寬,那么你可以旋轉它:
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);

android:id="@+id/iv_photo"

android:layout_width="320dip"   

android:layout_height="wrap_content"/>

使用它可能有效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM