カメラでキャプチャした写真の向きを取得する (その2)
さて、昨日の続き。
androidのカメラでキャプチャした写真の向き(Orientation)はその写真のExifタグデータを取得することで得ることができる。※
ExifInterface
http://developer.android.com/reference/android/media/ExifInterface.html
androidではExifタグデータを取得するためにExifInterfaceクラスが用意されており、OrientationはExifInterfaceクラスを経由して簡単に取得することができる。
int degree = 0; ExifInterface exifInterface = new ExifInterface("写真を保存しているパス"); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; break; default: break; }
degreeには回転角度がセットされる。
これで解決だと思ったのだが、そうは問屋が卸さない。
GALAXY Nexusの場合、上記コードでテストするとExifタグ中の写真の向きを示すorientationには0しか戻ってこないのである。これでは向きが全く分からない。
うーん。これは困った。
※androidのカメラでキャプチャされたデータはデフォルトではjpgフォーマットで保存されるからだ。