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