我在 google 和 stackoverflow 上没有找到我真正需要的东西, 我想了解我刚刚从相机拍摄的照片是垂直的还是水平的, 代码:
path_img= ("image_url");
Bitmap photo = null ;
photo = BitmapFactory.decodeFile(path_img );
int imageHeight = photo.getHeight();
int imageWidth = photo.getWidth();
当我在手机上拍摄照片时,imageHeight 和 imageWidht 始终相同,我的意思是,如果我拍摄垂直或水平照片,它始终为 960x1280,我想要水平照片尺寸为(宽度:960 高度:1280),垂直尺寸为(宽度) :1280 高度:960) 谢谢
最佳答案
使用ExifInterface获得如下方向:
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
boolean isVertical = true ;
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
isVertical = false ;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
isVertical =false ;
break;
}
依此类推,您可以从 ExifInterface 文档中的常量中获取所需的所有内容。
然后您可以尝试使用 Picasso 执行以下操作API:
int imageWidth , imageHeight = 0 ;
if(isVertical ) {
imageWidth =1280;
imageHeight=960;
}else if (!isVertical ){
imageWidth =960;
imageHeight=1280;
}
Picasso.with(getActivity())
.load(imageUrl)
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.resize(imageWidth , imageHeight)
.centerInside()
.into(imageView);
请给我一些反馈。
希望有帮助。
关于java - 如何理解位图照片是垂直还是水平?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21424846/