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:
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
use the ExifInterface to get the orientation as the following :
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 .
then you can try to do somthing as the following using the 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)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.