안드로이드 부분(삼성) 핸드폰 촬영 후 사진 회전 문제 해결 방안
3822 단어 사진 찍고 사진 돌리기.
/**
*
*
* @param path
*
* @return
*/
private
int
getBitmapDegree(String path) {
int
degree =
0
;
try
{
// , EXIF
ExifInterface exifInterface =
new
ExifInterface(path);
//
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
;
}
}
catch
(IOException e) {
e.printStackTrace();
}
return
degree;
}
2. 그림을 어느 각도에 따라 회전시킨다
/**
*
*
* @param bm
*
* @param degree
*
* @return
*/
public
static
Bitmap rotateBitmapByDegree(Bitmap bm,
int
degree) {
Bitmap returnBm =
null
;
// ,
Matrix matrix =
new
Matrix();
matrix.postRotate(degree);
try
{
// ,
returnBm = Bitmap.createBitmap(bm,
0
,
0
, bm.getWidth(), bm.getHeight(), matrix,
true
);
}
catch
(OutOfMemoryError e) {
}
if
(returnBm ==
null
) {
returnBm = bm;
}
if
(bm != returnBm) {
bm.recycle();
}
return
returnBm;
}
오케이, 위의 두 가지 방법으로 해결할 수 있어!