【问题标题】:How can I understand bitmap photo is vertical or horizontal?如何理解位图照片是垂直的还是水平的?
【发布时间】:2014-01-29 07:36:51
【问题描述】:

我在 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) 谢谢

【问题讨论】:

  • 那么你必须从你从相机得到的位图创建另一个位图

标签: java android bitmap android-bitmap


【解决方案1】:

使用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);

请给我一些反馈。

希望对您有所帮助。

【讨论】:

  • 问题是我如何理解垂直或水平?因为我捕获图像以垂直或水平握住我的手机,所以位图总是显示相同的值,
【解决方案2】:

我想你可以对高度和宽度做一个简单的测试,比如:

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)
}

【讨论】:

  • imageHeight 和 imageWidth 总是相同的值我的意思是它们是 1280x960 我的意思是如果我捕获图像 imageWidth=1280 并且重量总是 960
猜你喜欢
  • 2012-03-09
  • 1970-01-01
  • 2021-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多