Android 如何在纵向模式下设置捕获的图像

Android 如何在纵向模式下设置捕获的图像,android,android-camera,Android,Android Camera,我正在开发一个应用程序,在这个应用程序中,我为用户提供了一个便利,用户可以使用他的移动相机拍照,然后我在Imageview中显示图像 现在的问题是,如果我在纵向模式或横向模式下拍摄图像,它总是在ImageView中将图像设置为横向模式,但我只希望图像设置为纵向模式。请帮我解决这个问题 任何帮助都是值得的 谢谢你那样使用 Matrix mat = new Matrix(); ExifInterface exif = new ExifInterface(yourimagepath); String

我正在开发一个应用程序,在这个应用程序中,我为用户提供了一个便利,用户可以使用他的移动相机拍照,然后我在Imageview中显示图像

现在的问题是,如果我在纵向模式或横向模式下拍摄图像,它总是在ImageView中将图像设置为横向模式,但我只希望图像设置为纵向模式。请帮我解决这个问题

任何帮助都是值得的

谢谢你那样使用

Matrix mat = new Matrix();

ExifInterface exif = new ExifInterface(yourimagepath);
String orientstring = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientstring != null ? Integer.parseInt(orientstring) : ExifInterface.ORIENTATION_NORMAL;
int rotateangle = 0;
if(orientation == ExifInterface.ORIENTATION_ROTATE_90) 
            rotateangle = 90;
if(orientation == ExifInterface.ORIENTATION_ROTATE_180) 
            rotateangle = 180;
if(orientation == ExifInterface.ORIENTATION_ROTATE_270) 
            rotateangle = 270;

mat.setRotate(rotateangle, (float) bmpPic.getWidth() / 2, (float) bmpPic.getHeight() / 2);

File f = new File(yourimagepath);       
Bitmap bmpPic = BitmapFactory.decodeStream(new FileInputStream(f), null, null); 
Bitmap bmpPic1 = Bitmap.createBitmap(bmpPic, 0, 0, bmpPic.getWidth(), bmpPic.getHeight(), mat, true);   
Matrix matrix=new Matrix();
imageView.setScaleType(ScaleType.MATRIX);   //required
matrix.postRotate((float) angle, pivX, pivY);
imageView.setImageMatrix(matrix);
对于exp:

matrix.postRotate( 90f, imageView.getDrawable().getBounds().width()/2, imageView.getDrawable().getBounds().height()/2)

这是一个很好的解决方案:

单线解决方案:

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

这将自动检测旋转并将图像放置在正确的方向


毕加索是一个非常强大的库,用于处理应用程序中的图像,包括:复杂的图像转换和最小的内存使用。加载可能需要一秒钟,但我只是在图像视图后面放了一些文字,上面写着“加载图像”,当图像加载时,它覆盖了文字。

,谢谢你的回答,但是如何将mat值添加到位图中,你可以发布代码片段吗,这里是pivX和pivY?很抱歉,在eclipse中没有看到postRotate()上的示例鼠标。您可以很容易地看到详细信息。虽然此链接可能会回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-@谢谢你的建议,我已经更新了我的帖子。
Picasso.with(context).load("file:" + photoPath).into(imageView);