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

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器