Ok so I have a class that extends SurfaceView and overrides
surfaceChanged – just calls startPreview
surfaceCreated – opens camera, edits params *, sets surfaceHolder
surfaceDestroyed – calls stopPreview, release camera
this all work great because when the orientation is Portrait:
from surfaceCreated *
m_camera = Camera.open();
Camera.Parameters p = m_camera.getParameters();
if (getResources().getConfiguration().orientation !=
Configuration.ORIENTATION_LANDSCAPE)
{
p.set("orientation", "portrait");
// CameraApi is a wrapper to check for backwards compatibility
if (CameraApi.isSetRotationSupported())
{
CameraApi.setRotation(p, 90);
}
}
However, everytime the orientation changes it calls Camera.open()… which as you may know is quite an expensive operation, causing the transitions to be not so smooth.
When i force the orientation to landscape, the preview is great. Create only gets called once which works because the preview is in landscape the camera is always what the user sees. However, I need a way to set the orientation of the actual picture taken when in portrait. When I force landscape though, the surface never gets recreated and the parameters are never set when the camera is held in portrait.
So how can I do one of the following (exclusively)?
-
Hold onto m_camera between onDestroy and onCreate when orientation changes so that the transition is smooth
-
Force landscape and detect orientation changes another way… rotating the final snaped picture if held in portrait.
Also, if I am off base can someone point me in a better direction? Thank you.
Best Answer
The way I implemented it:
And then in your PictureCallback set metadata to indicate rotation level:
I hope it helps.
UPDATE Now when landscape based devices are appearing an additional check for it is required in OrientationEventListener.
Full code (a bit wasteful by LC, but easily demonstrates the approach)