4

I've tried every way to accomplish my desired behaviour but nothing seems to work.

My app is locked in portrait mode (I don't want a landscape UI) but I want to be able to switch the camera display to show a camera preview in portrait and landscape mode alternatively.

I'm not interested in capturing images.

To show the preview in portrait I simply do:

camera.setDisplayOrientation(90);

and my preview works fine, but, when I try to show the camera preview in landscape mode, I do:

camera.setDisplayOrientation(0);

and the preview actually rotates, but the image from camera is not rotated, and the final result is just a portrait image rotated to landscape.

I've tried every way:

1) rotate the camera with parameters.setRotation() but this affects only the final image saved and has nothing to do with the preview;

2) set parameters.set("orientation", "landscape") but this seems to have no effect (maybe an old and not yet supported command?);

3) set every combination of the methods below, but nothing, the only way to effectively rotate the image originate from camera seems to be physically rotate my device…

This is a practical demonstration of what I mean:

enter image description here

enter image description here

enter image description here

enter image description here

As you can see, parameters.setRotation() do not have effect on the preview, that is correct when is in portrait, but is simply rotate in landscape 'cause the camera don't rotate itself, but just place the portrait image rotated.

So, is there a way to show a camera preview in landscape when the app is in portrait?

Thanks.

shaithana
  • 2,470
  • 1
  • 24
  • 37
  • Have you seen this question - http://stackoverflow.com/questions/16128608/camera-preview-is-in-portrait-mode-but-image-captured-is-rotated – Oleksandr Aug 28 '15 at 12:40
  • @Alexandr yes, but as I say in my question, my problem it's not the final saved image (I'm not interested in capture image) but just the preview. – shaithana Aug 28 '15 at 13:49

1 Answers1

0

Check out this method to set orientation of camera. The parameter orientation is Display.getRotation(), you could change set it as per your requirement.:

public void setCameraOrientation(int orientation) {
    int orientationDegree = 0;
    switch (orientation) {
        case Surface.ROTATION_0:
            orientationDegree = 0;
            break;
        case Surface.ROTATION_90:
            orientationDegree = 90;
            break;
        case Surface.ROTATION_180:
            orientationDegree = 180;
            break;
        case Surface.ROTATION_270:
            orientationDegree = 270;
            break;
    }
    int displayOrientation = (cameraInfo.orientation - orientationDegree + 360) % 360;
    camera.setDisplayOrientation(displayOrientation);
    Camera.Parameters parameters = camera.getParameters();
    parameters.setRotation(displayOrientation);
    camera.setParameters(parameters);
}

For the whole context check out my camera demo app here. Specifically CameraPreview class.

Abdullah
  • 7,143
  • 6
  • 25
  • 41
  • **my app is locked in portrait**, and as I say in my **point 1**, `parameters.setRotation()` do not have effect on the preview image, just in the final capture. I've updated my question with practicals demonstrations. – shaithana Aug 28 '15 at 15:02