android camera portrait orientation
Asked Answered
M

3

8

I am using camera in my app. I am just using intent to start camera

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(cameraIntent, 101);

The captured image automatically comes in landscape view. How do i make camera to capture images in portrait view

Maelstrom answered 15/12, 2011 at 6:45 Comment(5)
i am facing the same issue, please tell me how do you solved this....Tartuffery
@SivaK Instead of using default camera app, i created my own camera view to capture imagesMaelstrom
Seshu Vinay - thanks for your reply, is there any sample code or blog for creating our own camera viewTartuffery
There's an answer below which gives some sample codeMaelstrom
Thanks - just now i gone through the FoodSpotting app, it uses the default camera, capturing photo in portrait and when the photo gets retrieved its in same portrait mode.... i will search for it...thanksTartuffery
P
13

If device has v2.2 or above you can rotate camera orientation to portrait using camera.setDisplayOrientation(90). In devices below to v2.2 the camera will only display in landscape orientation and thus image will come in landscape. Check these posts Using Camera in Portrait Orientation, Camera is wrong unless keyboard is open.

Pricefixing answered 15/12, 2011 at 6:57 Comment(1)
I don't think this will work without actually overriding the camera class - calling an intent won't be enough hereChura
F
2

try this.

        Parameters param = mCamera.getParameters();

        switch(mDisplay.getRotation()){
        case Surface.ROTATION_0:
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO){
                mCamera.setDisplayOrientation(90);
                Log.d("Rotation_0", "whatever");
            }
            else{
                Log.d("Rotation_0", "whatever");
                param.setRotation(90);
                mCamera.setParameters(param);
            }
            break;
        case Surface.ROTATION_90:
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO){
                mCamera.setDisplayOrientation(0);
                Log.d("Rotation_0", "whatever");
            }
            else{
                Log.d("Rotation_90", "whatever");
                param.setRotation(0);
                mCamera.setParameters(param);
            }
            break;
        }
Flower answered 15/12, 2011 at 7:15 Comment(0)
A
1

Here, this code is suitable for all types of orientation that are supported in android camera application[Portrait mode] too.

int rotation = this.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;

switch (rotation) {

    case Surface.ROTATION_0:
        degrees = 0;
        break;

    case Surface.ROTATION_90:
        degrees = 90;
        break;

    case Surface.ROTATION_180:
        degrees = 180;
        break;

    case Surface.ROTATION_270:
        degrees = 270;
        break;

}
Aggregate answered 21/9, 2015 at 11:11 Comment(1)
Thanks Tim CastelijnsAggregate

© 2022 - 2024 — McMap. All rights reserved.