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

kablu
  • 629
  • 1
  • 7
  • 26
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109
  • i am facing the same issue, please tell me how do you solved this.... – Siva K Oct 08 '12 at 11:15
  • @SivaK Instead of using default camera app, i created my own camera view to capture images – Seshu Vinay Oct 08 '12 at 11:27
  • 1
    Seshu Vinay - thanks for your reply, is there any sample code or blog for creating our own camera view – Siva K Oct 08 '12 at 12:09
  • There's an answer below which gives some sample code – Seshu Vinay Oct 08 '12 at 12:18
  • 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...thanks – Siva K Oct 08 '12 at 12:35

3 Answers3

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.

Community
  • 1
  • 1
anujprashar
  • 6,263
  • 7
  • 52
  • 86
  • 1
    I don't think this will work without actually overriding the camera class - calling an intent won't be enough here – ekatz Feb 11 '13 at 17:26
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;
        }
lv0gun9
  • 591
  • 7
  • 23
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;

}
Tim
  • 41,901
  • 18
  • 127
  • 145
Harrish Android
  • 262
  • 1
  • 3
  • 11