마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

sufaceview로 만든 카메라로 찍은 사진을 90도 회전시키고 싶어요

0 추천

사진은 잘 저장되는데 찍힌 사진을 보니 옆으로 누워있더군요

검색해보니 

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;
	}

위와 같은 방식으로 회전이 가능하다고 하네요

그런데 왜 저는 회전이 안되는걸까요?

메모리가 모자라서 그런가 싶어서 토스트를 달아서 예외처리발생여부를 확인했는데 그건아니더라구요

코드한번만 봐주세요....

익명사용자 님이 2014년 11월 11일 질문

1개의 답변

0 추천
aucd29 (218,390 포인트) 님이 2014년 11월 11일 답변
...