【问题标题】:Android sending captured image rotates 90 degree in some devicesAndroid 在某些设备中发送捕获的图像会旋转 90 度
【发布时间】:2013-01-09 09:47:36
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    你使用:

    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);
    

    看看你会得到什么。

    【讨论】:

      【解决方案2】:

      我使用以下代码解决了我的问题。

      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;
          }
      }
      

      感谢您的回复亲爱的朋友...

      【讨论】:

        【解决方案3】:

        请检查您的图片是否旋转了 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;
        }
        

        【讨论】:

          猜你喜欢
          • 2021-06-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-12-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多