Android - Imageview显示从画廊的图片在“横向”
题
首先,也许“景观”不是更好的描述,但我不能在此刻思考另一个。
我正在使用以下代码在imageview中显示图像,但我的映像在“肖像”(Readul)中拍摄了“纵向”(返回)显示Sidelong。
我的代码:
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"/>
.
是,“内容://媒体/外部/图像/媒体/ 7”是有效路径。
任何想法?
解决方案
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);
其他提示
android:id="@+id/iv_photo"
android:layout_width="320dip"
android:layout_height="wrap_content"/>
Use this it may works
不隶属于 StackOverflow