2

I have a surface view displaying a camera preview which looks good in landscape mode, but when I rotate my phone to portrait the surface view rotates and the camera preview is on its side which looks wrong.

When I fix my application orientation to landscape in my AndroidManifest.xml, the surface view behaves how I want it to, in that it doesn't rotate and the camera preview works great.

The problem is that I have other objects on the screen which need to rotate with the phone's orientation, which now doesn't because I've set the orientation to landscape.

Can anyone help me with a way to get everything apart from the surface view to rotate when the phone rotates, or if that is not possible a way to get the current physical orientation of the phone when the applications orientation is set to landscape, so that I can rotate my other objects manually.

Thanks, Andrew

Quango
  • 9,088
  • 5
  • 38
  • 72
Andrew Partis
  • 21
  • 1
  • 2
  • You may try this, possible to solve your problem. [android camera surfaceview orientation][1] [1]: http://stackoverflow.com/questions/5157984/android-camera-surfaceview-orientation – Nonoroazoro Jan 30 '13 at 08:56

2 Answers2

0

Camera.Parameters have a setRotation() method. Use it to rotate the camera when you change from landscape to portrait and vice versa. Then you don't have to bother about separating your layouts from the surface view.

pumpkee
  • 3,337
  • 2
  • 25
  • 34
  • Thanks for the quick response. I've tried rotating the camera using setRotation, but the preview still displayed in the incorrect rotation. I tried using params.set("rotation", 0), i've tried both at once, i tried stopping the preview before making the change and starting it again, but none of that has worked. – Andrew Partis May 07 '11 at 11:03
  • take a look at this: http://stackoverflow.com/questions/5157984/android-camera-surfaceview-orientation – pumpkee May 07 '11 at 11:41
0
public void surfaceDestroyed(SurfaceHolder holder){
    if(mCamera!=null){ 
        mCamera.stopPreview(); 
        mCamera.setPreviewCallback(null); 
        mCamera.release();       
        mCamera=null; 

    }
}
lv0gun9
  • 537
  • 5
  • 18