【问题标题】:How to get orientation of device in android?如何在android中获取设备的方向?
【发布时间】:2012-05-21 13:34:36
【问题描述】:

我在 imageview 中显示图像,该图像是由 android 相机的 Intent 方法捕获的。我已经在三星 Nexus 上测试过这段代码,但是当我在 Nexus S 上测试时,图像会自行旋转 270 度。我已经浏览了这些链接

ACTION_IMAGE_CAPTURE orientation problem on Nexus S and Samsung Galaxy S I9000

Camera/picture orientation in Android

http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setRotation%28int%29

Picture orientation from gallery/camera intent

但是这段代码

ExifInterface exif = new ExifInterface("filepath");
exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

在两个设备中总是给出 0。请告诉我我是否知道图像在显示时以特定设备的哪个角度显示,以便它将应用于所有设备,一旦我得到它的角度,我将自己旋转。提前致谢。

【问题讨论】:

标签: android android-intent imageview


【解决方案1】:

我不能 100% 确定我了解您要查找的内容,但如果您想要设备的方向,请查看以下问题:

Check orientation on Android phone

【讨论】:

  • 我试过 getResources().getConfiguration().orientation。但在两台设备上仍然是相同的结果 1。
  • 你到底想做什么?因为如果你只是想设置方向,而不是检查当前的方向,那应该会容易一些。
【解决方案2】:

如果你:

ExifInterface exif = new ExifInterface("filepath");
exif.getAttribute(ExifInterface.TAG_ORIENTATION);

?

【讨论】:

  • 在两个设备中总是给出 0。 Nexus 显示良好,Nexus S 显示横向或旋转图像。
  • 你读过这个:stackoverflow.com/questions/8450539/… 吗?
  • 似乎有一个错误解释了您提到的 exif 标签行为。
  • 是的!我读了那个。但它在这一行上给出运行时错误 Cursor mediaCursor = content.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE }, MediaStore.MediaColumns.DATE_ADDED + ">=?", new String[]{String.valueOf(captureTime/1000 - 1)}, MediaStore.MediaColumns.DATE_ADDED + "desc");
  • 你有这方面的信息吗?堆栈跟踪?也许您只是缺少权限。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-05
  • 1970-01-01
相关资源
最近更新 更多