繁体   English   中英

如何了解位图照片是垂直还是水平的?

[英]How can I understand bitmap photo is vertical or horizontal?

我没有在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),垂直照片为(width: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文档中的Constants所需的全部内容。

那么您可以尝试使用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);

请给我一些反馈。

希望泰勒有所帮助。

我想您可以像这样对高度和宽度做一个简单的测试:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM