【发布时间】: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();
我查看推特照片选择器,它显示的图片完全真实。我的问题在哪里。谢谢
【问题讨论】:
标签: android android-fragments android-imageview