2

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.....

Haris
  • 13,645
  • 12
  • 90
  • 121

1 Answers1

2

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

Community
  • 1
  • 1
Juned
  • 6,290
  • 7
  • 45
  • 93
  • Hi..Thanks for your reply.....I tried the above but still the image is rotated... – Haris Oct 22 '12 at 07:32
  • if you used this code then now i think you should remove all the code which is related to rotation. – Juned Oct 22 '12 at 07:49
  • 2
    camera.setDisplayOrientation(90) this worked for Android ICS and Above, but not for 2.3.6, In the doc it says "'setDisplayOrientation()' is for Android 14 and up" hope you will change the answer – Amalan Dhananjayan Apr 01 '13 at 07:24