사진은 잘 저장되는데 찍힌 사진을 보니 옆으로 누워있더군요
검색해보니
String outUriStr = MediaStore.Images.Media.insertImage(
getContentResolver(), bitmap, null,
null);
Bitmap image = BitmapFactory.decodeFile(outUriStr);
// 이미지를 상황에 맞게 회전시킨다
ExifInterface exif = new ExifInterface(outUriStr);
int exifOrientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int exifDegree = exifOrientationToDegrees(exifOrientation);
image = rotate(image, exifDegree);
public int exifOrientationToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
return 90;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
return 180;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
return 270;
}
return 0;
}
/**
* 이미지를 회전시킵니다.
*
* @param bitmap
* 비트맵 이미지
* @param degrees
* 회전 각도
* @return 회전된 이미지
*/
public Bitmap rotate(Bitmap bitmap, int degrees) {
if (degrees != 0 && bitmap != null) {
Matrix m = new Matrix();
m.setRotate(degrees, (float) bitmap.getWidth() / 2,
(float) bitmap.getHeight() / 2);
try {
Bitmap converted = Bitmap.createBitmap(bitmap, 0, 0,
bitmap.getWidth(), bitmap.getHeight(), m, true);
if (bitmap != converted) {
bitmap.recycle();
bitmap = converted;
}
} catch (OutOfMemoryError ex) {
Toast.makeText(getApplicationContext(), "예외발생", 1000).show();
// 메모리가 부족하여 회전을 시키지 못할 경우 그냥 원본을 반환합니다.
}
}
return bitmap;
}
위와 같은 방식으로 회전이 가능하다고 하네요
그런데 왜 저는 회전이 안되는걸까요?
메모리가 모자라서 그런가 싶어서 토스트를 달아서 예외처리발생여부를 확인했는데 그건아니더라구요
코드한번만 봐주세요....