Android的 - ImageView的显示图像从画廊"景观" [英] Android - ImageView showing image from Gallery in "landscape"
问题描述
首先,在所有的,也许风景是不是更好的词来形容,但我想不出另外一个在当下。
First at all, maybe "landscape" isn't the better word to describe, but i can't think another one in the moment.
我用下面的code,显示在ImageView的图像,但我认为在纵向采取与设备的图像(头抬起)是显示瞟。
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.
我的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"/>
是的,内容://媒体/外部/图像/媒体/ 7是一个有效的路径。
And yes, "content://media/external/images/media/7" is a valid path.
任何想法?
推荐答案
只需查看图像的尺寸,如果它长得比它更宽,那么你可以旋转:结果
http://android-er.blogspot.com /2010/07/rotate-bitmap-image-using-matrix.html
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
相关位是:
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的 - ImageView的显示图像从画廊&QUOT;景观&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!