[英]How can I understand bitmap photo is vertical or horizontal?
I did not find what I really need on google and stackoverflow, I want to understand that a photo which I just capture from the camera is vertical or horizontal, Code: 我没有在google和stackoverflow上找到我真正需要的东西,我想了解一下我刚刚从相机捕获的照片是垂直还是水平的,代码:
path_img= ("image_url");
Bitmap photo = null ;
photo = BitmapFactory.decodeFile(path_img );
int imageHeight = photo.getHeight();
int imageWidth = photo.getWidth();
When I capture the photo on my phone imageHeight and imageWidht always same I mean if I capture photo vertical or horizantal it is always 960x1280, I want to horizantal photo size is (width:960 height:1280) and vertical is (width:1280 height:960) thanks 当我在手机上捕获照片时imageHeight和imageWidht始终相同,我的意思是如果我捕获垂直或水平的照片始终为960x1280,则我希望水平的照片大小为(宽度:960高度:1280),垂直照片为(width:1280高度:960)谢谢
use the ExifInterface to get the orientation as the following : 使用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;
}
and so on for the all what you need from the Constants that are in the ExifInterface documentation . 以此类推,以获取ExifInterface文档中的Constants所需的全部内容。
then you can try to do somthing as the following using the Picasso API : 那么您可以尝试使用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);
and please give me some feedback . 请给我一些反馈。
Hope taht helps . 希望泰勒有所帮助。
I guess you could just do a simple test of the height and width like: 我想您可以像这样对高度和宽度做一个简单的测试:
if(imageHeight > imageWidth){
//Image is horizontal (according to your comments, horizontal photos are usually wider than the hight)
}
elseif(imageHeight > imageWidth){
//Image is horizontal (again, according to your comments)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.