Android的 - 找到照片的方向是把照相机 [英] Android - Find the orientation of photo was took by camera

查看:132
本文介绍了Android的 - 找到照片的方向是把照相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要拍照,找出它的方向,绘制在画布上,并旋转画布。我需要帮助找出照片的方向

I need to take a photo, find out its orientation, draw it on canvas and rotate the canvas. I need help to find out orientation of the photo

推荐答案

您需要使用嵌入照片中的EXIF标签:

You need to use the EXIF tag embedded in the photo:

private int getExifOrientation() {
  ExifInterface exif;
  int orientation = 0;
  try {
    exif = new ExifInterface( mImagePath );
    orientation = exif.getAttributeInt( ExifInterface.TAG_ORIENTATION, 1 );
  } catch ( IOException e ) {
    e.printStackTrace();
  }
  Log.d(TAG, "got orientation " + orientation);
  return orientation;
}

但是,返回的实际EXIF值几分怪异。它允许对各种旋转和镜像。最好的参考我发现是这里。在一般情况下,后,你的方向,你要通过查找功能,运行它来获取度的旋转:

However, the actual EXIF value returned is sorta weird. It allows for all variety of rotation and mirroring. The best reference I've found is here. In general, after you get the orientation, you'll want to run it through a lookup function to get the rotation in degrees:

private int getBitmapRotation() {
  int rotation = 0;
  switch ( getExifOrientation() ) {
    case ExifInterface.ORIENTATION_ROTATE_180:
      rotation = 180;
      break;
    case ExifInterface.ORIENTATION_ROTATE_90:
      rotation = 90;
      break;
    case ExifInterface.ORIENTATION_ROTATE_270:
      rotation = 270;
      break;
  }

  return rotation;
}

这篇关于Android的 - 找到照片的方向是把照相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆