I'm developing a small camera capture program in android.
I didn't use the Intent
to open the camera and show it's images. I'm using the camera directly:
if (myPreviewRunning) {
myCamera.stopPreview();
myPreviewRunning = false;
}
Camera.Parameters parameters = myCamera.getParameters();
display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
display = getWindowManager().getDefaultDisplay();
Camera.Size optimalSize = getOptimalSize(parameters.getSupportedPreviewSizes(), width, height);
parameters.setPreviewSize(optimalSize.width, optimalSize.height);
if (display.getRotation() == Surface.ROTATION_0 ||display.getRotation() == Surface.ROTATION_270)
{
parameters.setPreviewSize(optimalSize.height, optimalSize.width);
ViewGroup.LayoutParams layoutParams = mySurfaceView.getLayoutParams();
layoutParams.width = optimalSize.height;
layoutParams.height = optimalSize.width;
mySurfaceView.setLayoutParams(layoutParams);
myCamera.setDisplayOrientation(90);
}
else
{
myCamera.setDisplayOrientation(180);
mySurfaceView.getLayoutParams().width = optimalSize.width;
mySurfaceView.getLayoutParams().height = optimalSize.height;
}
myCamera.setParameters(parameters);
myCamera.setPreviewDisplay(holder);
myCamera.startPreview();
Until now, with this code I'm able to rotate the camera to a 'natural' behaviour, so when I rotate the cell phone to landscape, it rotates the image and you see it in landscape. But due to some reasons, I need the preview image to remain in portrait mode, even if I put landscape.
How can I force the camera preview to remain in portrait mode?
EDIT: AndroidManifest.xml
<activity
android:name="CameraViewer"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
I want to be able to do this: