Android 发送捕获的图像在某些设备中旋转 90 度

标签 android android-intent android-camera android-image android-camera-intent

我正在开发 Android 应用程序。在我的应用程序中,我必须捕获图像并将该图像发送到服务器。在某些设备中,捕获的图像以 90 度旋转发布在服务器中。我在 stackoverflow 和其他一些网站中搜索了修复程序。我得到了解决方案 ..我使用了所有解决方案 例如:

Uri selectedImage = data.getData();


File imageFile = new File(selectedImage.toString());
ExifInterface exif;
try {
exif = new ExifInterface(imageFile.getAbsolutePath());

int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:

rotate=90;

    break;
    case ExifInterface.ORIENTATION_ROTATE_180:

    rotate=180;
 break;
            }

但不幸的是,我在每台设备上的方向始终为 0。即使在 90 度旋转的图像设备中。

请帮助解决我的问题的 friend 。

最佳答案

您使用:

int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

因此,您发送 defaultValue ExifInterface.ORIENTATION_NORMAL。也许您的 exif 没有属性 TAG_ORIENTATION(或 ORIENTATION_UNDEFINED)而您得到默认值?

尝试:

int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);

看看你得到了什么。

关于Android 发送捕获的图像在某些设备中旋转 90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14232328/

相关文章:

android - Kotlin中emptyList的作用是什么

android - Activity 不显示在最近的 android 中

android - Android Studio错误:(1,0)找不到ID为 'com.android.application'的插件

android - 如何获取发送 Intent Activity 的名称?

如果手机处于横向模式,Android 相机预览方向不正确

java - 无法使用散列密码登录 Android 应用程序

java - 为什么运行应用程序时出现 fatal error ?

android - 如何将回调函数从 Activity 内的一个 fragment 传递到第二个 Activity?

android - Android 2.3 相机方向不变

android - 三星 Galaxy SIII 的相机是否存在缺陷?