简体   繁体   English

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

[英]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.

相关问题 如何设置JLabel的垂直/水平高度? (Netbeans的) - How can I set the vertical/horizontal height of a JLabel? (Netbeans) 如何筛选完全垂直的尺寸和完全水平的尺寸? - How can I screen a full vertical size with exactly horizontal size? 如何检测照片是否垂直拍摄? (我找到了一种方法,但是没有用) - How can I detect photo is taken vertical or not? (I find a way but it does not work) 如何在水平RecyclerView中基于Vertical RecyclerView标题设置相同的值 - How Can I Set Same value In Based on Vertical RecyclerView heading In Horizontal RecyclerView 我试图用多条水平线和垂直线绘制一个圆圈,但遇到了障碍。 我怎样才能让这个运行 - I'm trying to draw a circle with multiple horizontal and vertical lines and i run into a roadblock. How can i make this run 带有垂直寻呼机的水平寻呼机。 我们怎么申请? - horizontal pager with vertical pager. How can we apply? 如何将垂直列表输出到水平列表中 - How do I output the vertical list into horizontal lists 如何将垂直和水平滚动条置于JScrollPane中心? - How do I center the vertical and horizontal scrollbars in a JScrollPane? 如何在 java 中将我的 output 从水平更改为垂直? - how do i change my output from horizontal to vertical in java? 修改位图后,如何修改“修改后的”位图等? - After modifying a Bitmap, how can I modify the “modified” Bitmap and so on?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM