Question

I am trying to use camera hardware to capture list of images. But while launching the Camera View the view doesn't looks like usual. The screen shot is attached below. I am testing this in HTC Sensation running android 4.0.3.

Image ScreenShot while in portrait enter image description here It doesn't looks like usual camera view.

What is the problem here?

Where i am doing wrong?

Was it helpful?

Solution

This is the usual problem with making a custom camera with Android in portrait mode. You likely have a SurfaceView that is being used to display your camera preview. I add the following line of code to my surfaceCreated method:

camera.setDisplayOrientation(90);

For more info, check out some other answers on this topic (here is one, and another). Basically, the Android camera is set to display in Landscape mode, so you need to rotate the orientation if the Activity is in portrait mode to accomodate this.

OTHER TIPS

By default the Hardware Camera is Landscape(almost many devices) , so at-once you capture , i automatically rotates to 90 degree - As if it is taken in the landscape .

Thats why you get the image right when you take in Landscape and 90degree rotated image while taking in Portrait mode .

  • detect the orientation of the device and if it is in portrait , rotate to 90 degree clockwise , so that it would tally when it rotates 90degree anti-clockwise .

Use the below code to detect the orientation ,

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) 
    {
        super.onRestoreInstanceState(savedInstanceState);
        if (savedInstanceState != null) 
        {
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
            {
                // code in portrait - rotate to 90 degree
            }
            else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            {
                    // code in landscape - do nothing
            }

        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top