SLaks 2013-05-21 09:47 采纳率: 0%
浏览 3051
已采纳

截取的图片上传到服务器上的时候会旋转90度

我做了一个安卓应用程序。在我的应用中,我要截取一个图片并把它发送到服务器上。在某种设备里,截取的图片上传到服务器上的时候会旋转90度。代码如下:

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

但是很不幸,在每个设备里我得到的orientation的值都是0,甚至图片旋转90度的那个设备上也是一样的结果。

  • 写回答

3条回答 默认 最新

  • SLaks 2013-05-22 07:20
    关注

    我用这个方法解决了问题:

       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;
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services