【问题标题】:Android Camera Image Height and Width return not trueAndroid 相机图像高度和宽度返回不正确
【发布时间】:2017-04-05 11:08:56
【问题描述】:

在我的项目中,我想将图像选择到图库中并将这些添加到回收视图中。但是,当我选择垂直手机相机拍照时,它会返回 反转高度和宽度。水平相机图像变为真实。顺便说一句,当有人从某个地方发送垂直图像时,它将返回 true。我看到日志,它说: D/height : 2322 , D/width: 4128 用于垂直图像。但恰恰相反。

这是我获取高度和宽度的代码:

public int drawableWidthFromPath(String path,int width)throws IOException{

        File imgFile = new File(path);
        int newWidth=0;

        if(imgFile.exists())
        {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
            int imageHeight = options.outHeight;
            int imageWidth = options.outWidth;


            Log.d("height", String.valueOf(imageHeight));
            Log.d("width", String.valueOf(imageWidth));


            newWidth = width*imageWidth/imageHeight;

        }


        return newWidth;
    }

此代码适用于:水平外包图像、垂直外包图像、水平相机图像,但不适用于垂直相机图像。顺便说一句,我试试

Bitmap x = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
x.getHeight();
x.getWidth();

但结果是一样的。这是关于我在做什么的一些 ss:

我查看推特照片选择器,它显示的图片完全真实。我的问题在哪里。谢谢

【问题讨论】:

    标签: android android-fragments android-imageview


    【解决方案1】:

    解决办法如下:

            switch(orientation) {
    
                case ExifInterface.ORIENTATION_ROTATE_90:
                    selectedBitmap =rotateImage(selectedBitmap, 90);
                    break;
    
                case ExifInterface.ORIENTATION_ROTATE_180:
                    selectedBitmap =  rotateImage(selectedBitmap, 180);
                    break;
    
                case ExifInterface.ORIENTATION_ROTATE_270:
                    selectedBitmap =  rotateImage(selectedBitmap, 270);
                    break;
    
                case ExifInterface.ORIENTATION_NORMAL:
                    selectedBitmap =  rotateImage(selectedBitmap, 0);
    
                default:
                    break;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多