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 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算