在某些设备上,Android发送捕获的图像时会旋转90度

在某些设备上,Android发送捕获的图像时会旋转90度,android,android-intent,android-camera,android-image,android-camera-intent,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

我正在开发一个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度旋转的图像设备中

请帮助解决我的问题,朋友。

您使用:

int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
因此,发送defaultValue ExifInterface.ORIENTATION\u NORMAL。也许您的exif没有属性TAG_ORIENTATION(或ORIENTATION_UNDEFINED),您得到了默认值

尝试:


看看你能得到什么。

我用下面的代码解决了我的问题

private int getImageOrientation(){
    final String[] imageColumns = { MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.ORIENTATION };
    final String imageOrderBy = MediaStore.Images.Media._ID+" DESC";
    Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            imageColumns, null, null, imageOrderBy);

    if(cursor.moveToFirst()){
        int orientation = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION));
        rotate=orientation;
        System.out.println("orientation==="+orientation);
        cursor.close();
        return orientation;
    } else {
        return 0;
    }
}

感谢您的回复亲爱的朋友们…

请检查您的图像是否以270度旋转 将此添加到switch语句中

switch(orientation) 
{
case ExifInterface.ORIENTATION_ROTATE_90:
rotate=90;

break;
case ExifInterface.ORIENTATION_ROTATE_180:

rotate=180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:

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

break;
case ExifInterface.ORIENTATION_ROTATE_180:

rotate=180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:

rotate=270;
break;
}