I know there are already questions like this, but none solved it. I took some help and figured out basic code that I need to change the camera with respect to the display. 

```
   cameraInfo=new Camera.CameraInfo();
                camera.getCameraInfo(camId,cameraInfo);
                int angle=0;
                int rotation = getActivity().getWindowManager().getDefaultDisplay()
                        .getRotation();
                switch(rotation)
                {
                    case Surface.ROTATION_0:
                        parameters.setPreviewSize(s.width, s.height);
                        Log.i(TAGR, "THE ROATTION IS 0");
                        camera.setDisplayOrientation(90);
                        break;
                    case Surface.ROTATION_90:
                        parameters.setPreviewSize(s.width, s.height);
                        Log.i(TAGR, "THE ROATTION IS 90");
                        camera.setDisplayOrientation(0);

                        break;
                    case Surface.ROTATION_180:
                        parameters.setPreviewSize(s.width, s.height);
                        Log.i(TAGR, "THE ROATTION IS 180");
                        camera.setDisplayOrientation(0);

                        break;
                    case Surface.ROTATION_270:
                        parameters.setPreviewSize(s.width, s.height);
                        Log.i(TAGR, "THE ROATTION IS 270");
                        camera.setDisplayOrientation(180);
                        break;
                    default:
                        camera.setDisplayOrientation(0);
                        break;
                }

            }

```

However, I am unable to get the correct display preview with respect to the rotation of the device. I have tried several different combination of angles. However, none gave me the correct output. I am attaching the images of my preview. Please explain the solution to the problem. Moreover, I want to know what position of my device corresponds to angles 0,90,180, and 270. In other words, is 0 corresponds to portrait or landscape orientation?.

Images :
The landscape is inverted in this one. I tried setting the rotation by 180 when ROTATION\_180. Doing so did not work out, as the other orientation (in landscape) became inverted [![The landscape in this orientation is inverted](https://i.stack.imgur.com/oUTne.jpg)](https://i.stack.imgur.com/oUTne.jpg)

The upside down orientation does not do anything. The desired result is to bring the click button down with correct preview. I don't have any idea why this is not working. I have tried several values in each rotation, but none solved this issue.

[![This is the upside down orientation of my phone](https://i.stack.imgur.com/Z5OdQ.jpg)](https://i.stack.imgur.com/Z5OdQ.jpg)

I am a beginner, so please explain in detail. Thanks.