Android Coding

전방카메라(셀카) 촬영 시, 해당 비트맵 회전 및 좌우처리

오마로 2017. 3. 10. 14:17
반응형



안드로이드 카메라 앱 개발


카메라 촬영 시 후방카메라(뒷면에 달린 카메라) 말고,

전방카메라(셀카용) 촬영 시, 해당 Bitmap을 가지고 올 때 이상하게 나오는 경우가 발생함.


그래서, 카메라 각도에 따른 설정으로 정상적으로 처리함

 

int rotate = cameraAngle;
/* 중앙 크롭 처리 */
if (mSrcBitmap.getWidth() > mSrcBitmap.getHeight()) {
mSrcBitmap = Bitmap.createBitmap(mSrcBitmap, mSrcBitmap.getWidth() / 2 - mSrcBitmap.getHeight() / 2, 0, mSrcBitmap.getHeight(), mSrcBitmap.getHeight()); // h < w 일 때, h기준으로 1:1 중앙 크롭
} else {
if (isDisplayExcepion) {
mSrcBitmap = Bitmap.createBitmap(mSrcBitmap, 0, mSrcBitmap.getHeight() / 2 - mSrcBitmap.getWidth() / 2, mSrcBitmap.getWidth(), mSrcBitmap.getWidth()); // h > w 일 때, w기준으로 1:1 중앙 크롭
} else {
mSrcBitmap = Bitmap.createBitmap(mSrcBitmap, mSrcBitmap.getHeight() / 2 - mSrcBitmap.getWidth() / 2, 0, mSrcBitmap.getWidth(), mSrcBitmap.getWidth()); // h > w 일 때, w기준으로 1:1 중앙 크롭
}
}

mSrcBitmap = Bitmap.createScaledBitmap(mSrcBitmap, mPreviewInfoBean.getImage_target_width(), mPreviewInfoBean.getImage_target_height(), true);

Matrix matrix = new Matrix();
/*세로모드 일 때 회전 처리 */
if (cameraAngle == 0 || orientation == 6) {
if (isDisplayExcepion) {
rotate = 0;
if(isFrontCamera){
matrix.postScale(-1,1);
matrix.postTranslate(mSrcBitmap.getWidth(),0);
}
} else {
rotate = 90;
if(isFrontCamera){
matrix.postScale(-1,1);
matrix.postTranslate(mSrcBitmap.getWidth(),0);
}
}
} else if (cameraAngle == 90) {
if (isDisplayExcepion) {
rotate = 0;
} else {
rotate = 180;
}
} else if (cameraAngle == 270) {
rotate = 0;
} else {
rotate = 90;
}


matrix.postRotate(rotate);

mSrcBitmap = Bitmap.createBitmap(mSrcBitmap, 0, 0, mSrcBitmap.getWidth(), mSrcBitmap.getHeight(), matrix, true);


전방카메라일 때, 각도 및 좌우 조정을 해서 정상처리하면 된다. 

if(isFrontCamera){
matrix.postScale(-1,1);
matrix.postTranslate(mSrcBitmap.getWidth(),0); }
matrix.postRotate(rotate);


몇 번 각도를 조정하면 무난하게 처리할 거라고 판단됩니다.


안드로이드는 너무 다양한 폰이 많아서, orientation 값이 지멋대로 임 쩝..

카메라 앱 개발의 길은 멀고도 재미난 여정인 것 같네요 ^^



반응형