LoginSignup
3
3

More than 5 years have passed since last update.

[Android] BitmapFactory.Optionsでwidthとheightが逆?と思ったら

Posted at

widthとheightが逆?

以下の様なコードでwidth、heightを取得したら
どう見ても縦長の画像なのにwidthのほうが大きい。。。

BitmapFactory.Options options = new BitmapFactory.Options();
BitmapFactory.decodeFile(imagePath, options);

int width = options.outWidth;
int height = options.outHeight;

結果

色々調べた結果、この画像のExifには”向きは90°回転だよ”って情報が入ってました。


try {
    ExifInterface ex = new ExifInterface(imagePath);
    // orienatation定義
    // 1    そのまま
    // 2    上下反転(上下鏡像?)
    // 3    180度回転
    // 4    左右反転
    // 5    上下反転、時計周りに270度回転
    // 6    時計周りに90度回転
    // 7    上下反転、時計周りに90度回転
    // 8    時計周りに270度回転
    String orientation = ex.getAttribute(ExifInterface.TAG_ORIENTATION);
     // →orientationが6だった

} catch (IOException e) {
}

なるほど、この場合、BitmapFactoryでは回転前の縦横長さが返ってきてたようですね。

3
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3