The logic here seems flawed. You return the image if its orientation is normal and rotate it in _all other_ cases, independent of whether it was rotated 90, 180, 270 degress, or flipped or whatever. You should turn that condition the other way around: Check for ORIENTATION_ROTATE_90, then rotate back and return. Return the original in _all other_ cases.