2
votes

For my application I am using android native camera and previewing the image using surface view. in my case everything is working except the camera orientation. When I open the camera by setting screenOrientation="landscape on manifest file I am getting the preview without any problem in landscape mode. But I need to take image in portrait mode, for this I changed my manifest like android:screenOrientation="portrait" and change my code like mCamera.setDisplayOrientation(90), params.set("orientation", "landscape"),params.set("rotation", 90), but still I am getting 90 degree rotated image. And my code is

  public void setupCamera(int width, int height) {
    Log.i(TAG, "setupCamera");
    synchronized (this) {
        if (mCamera != null) {
            Camera.Parameters params = mCamera.getParameters();
            List<Camera.Size> sizes = params.getSupportedPreviewSizes();
            List<Camera.Size> imgsize=params.getSupportedPictureSizes();
            mFrameWidth = width;
            mFrameHeight = height;

           // mCamera.setDisplayOrientation(90);
            params.set("orientation", "landscape");
             params.set("rotation", 90);
            // selecting optimal camera preview size
            {
                int  minDiff = Integer.MAX_VALUE;
                for (Camera.Size size : sizes) {
                    if (Math.abs(size.height - height) < minDiff) {
                        mFrameWidth = size.width;
                        mFrameHeight = size.height;
                        minDiff = Math.abs(size.height - height);
                    }
                }
            }

            params.setPreviewSize(getFrameWidth(), getFrameHeight());




            List<String> FocusModes = params.getSupportedFocusModes();
            if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO))
            {
                params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
            }            

            mCamera.setParameters(params);



            mCamera.startPreview();
        }
    }
}

I am using Micromax A 52 model... Any one please help.....

1

1 Answers

2
votes

If your application runs on v2.2 or above you can rotate camera orientation to portrait using camera.setDisplayOrientation(90).

For others:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

//After opening camera - call via reflection
Method rotateMethod = android.hardware.Camera.class.getMethod("setDisplayOrientation", int.class);
rotateMethod.invoke(mCamera, 90);

for more details please refer this link and this
Hope this will be helpful