0
當我使用自定義照相機拍攝照片時,我無法更改圖片方向。我想手動處理方向。我不知道如何調用Camera.PictureCallback時如何旋轉onConfigurationchanged中的圖片。我沒有拍攝照片時成功更改了方向。我沒有在任何圖像視圖中設置圖像,而是在表面視圖中顯示它。這是我設置的FrameLayout和表面爲它的代碼:Android如何在拍攝照片時根據方向旋轉照片自定義照相機
Framelayout camera_view = (FrameLayout) findViewById(R.id.camera_view);
CameraSurfaceCreater mCameraView = new CameraSurfaceCreater(this, mCamera, CameraSetter.this);//create a SurfaceView to show camera data
camera_view.addView(mCameraView);//add the SurfaceView to the layout
時拍攝照片:
Camera.PictureCallback mPicture = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
pictaken = true;
}
};
和onConfiguration更改:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
if(!isPictureTaken){
setCameraDisplayOrientation(CameraSetter.this, 0, mCamera);
}else {
//dont know how to rotate a photo when picture is taken
}
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
if(!isPictureTaken){
setCameraDisplayOrientation(CameraSetter.this, 0, mCamera);
}
}
}
任何幫助表示讚賞。是否必須旋轉framelayout或拍攝照片後用戶更改方向後必須執行的操作。
感謝您的回答。但我應該在代碼中添加此OrientationEventListener?或者我應該刪除onconfigurationchanged? – exceptionnotgood
您可以在onCreate()中添加此代碼,但請確保在相機初始化後使用此代碼。從onResume()啓用此功能並從onPause()中禁用。 –
這有一個問題,即當您拍攝照片並且設備移動到風景照片時,它將被移除,並且會再次打開相機。 – exceptionnotgood