从图库/相机意图照片方向 [英] Picture orientation from gallery/camera intent

查看:163
本文介绍了从图库/相机意图照片方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到的图片从相机/画廊的意图我的应用程序。在许多手机的画面,我的意图读/乌里已经旋转到正确的方向。例如N1,联想,欲望是这样的话。

I'm getting picture to my app from camera / gallery intent. In many phones picture that I read from the intent / Uri is already rotated to correct orientation. For example N1, Legend, Desire that is the case.

但随后在某些手机上(例如Milestone1,的GalaxyS)画面总是在景观更无论哪种方式的图片拍摄。这意味着,在我的应用程序人像图片psented错误的方式给用户$ P $。我试图读取图片的EXIF信息,但方向标记始终为0。必须有一个办法,找出图片的正确的方向,因为在Milestone1 Gallery应用程序正确显示的人像照片。

But then on some phones ( for example Milestone1, GalaxyS) the picture is always in landscape more no matter which way the picture was taken. This means that in my application portrait picture is presented wrong way to the user. I tried to read EXIF info of the picture but orientation tag is always 0. There has to be a way to find out the right orientation of the picture because in Milestone1 the gallery application shows the portrait pictures correctly.

我如何知道我是否需要显示给用户之前,旋转图片自己?

How do I know if I need to rotate the picture myself before showing it to the user?

感谢您对您的帮助!

推荐答案

弗洛里安的答案是工作画廊图像。

Florian answer is working for gallery images.

下面code适用于捕捉的图像,没有带试图与画廊的图像,但我相信它应该工作。希望这可以帮助任何人。

The following code works for captured images, havn't tried with gallery images but i believe it should work. Hope this helps anybody.

code:

     public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath){
     int rotate = 0;
     try {
         context.getContentResolver().notifyChange(imageUri, null);
         File imageFile = new File(imagePath);
         ExifInterface exif = new ExifInterface(
                 imageFile.getAbsolutePath());
         int orientation = exif.getAttributeInt(
                 ExifInterface.TAG_ORIENTATION,
                 ExifInterface.ORIENTATION_NORMAL);

         switch (orientation) {
         case ExifInterface.ORIENTATION_ROTATE_270:
             rotate = 270;
             break;
         case ExifInterface.ORIENTATION_ROTATE_180:
             rotate = 180;
             break;
         case ExifInterface.ORIENTATION_ROTATE_90:
             rotate = 90;
             break;
         }


         Log.v(TAG, "Exif orientation: " + orientation);
     } catch (Exception e) {
         e.printStackTrace();
     }
    return rotate;
 }

编辑: 由于可以读到的评论,有些设备不支持Exif信息,没有带检查它,但我认为HTC没有。一定要检查哪些设备,并创建一个替代。

As can be read in the comments, some devices do not support Exif information, havn't checked which but i think HTC doesn't. be sure to check what devices and create an alternative.

这篇关于从图库/相机意图照片方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆