1

I'm using the following custom SurfaceView for some AR task. I set android:screenOrientation="portrait" for my activity in the AndroidManifest, but the image is rotated by 90 deg with weird aspect ratio. I'm using a Samsung Galaxy S...

Anybody can help?

public class CustomCameraView extends SurfaceView
{
    Camera camera;
    SurfaceHolder previewHolder;

    SurfaceHolder.Callback surfaceHolderListener = new SurfaceHolder.Callback() {
        public void surfaceCreated(SurfaceHolder holder) {
            try {
                camera = Camera.open();
                camera.setPreviewDisplay(previewHolder);
            } catch (IOException e) {
                e.printStackTrace();
            }       
        }

        public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int w, int h)
        {
            Parameters params = camera.getParameters();
            params.setPreviewSize( 800, 480);
            params.setPictureFormat(PixelFormat.JPEG);
            camera.setParameters(params);
            camera.startPreview();
        }

        public void surfaceDestroyed(SurfaceHolder arg0)
        {
            camera.stopPreview();
            camera.release();
        }
    };

    public CustomCameraView(Context context)
    {
        super(context);

        previewHolder = this.getHolder();
        previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        previewHolder.addCallback(surfaceHolderListener);
    }

    protected void onDraw (Canvas canvas)
    {
        super.onDraw(canvas);
    }

    public void closeCamera()
    {
        if(camera != null)
            camera.release();
    }
}
jul
  • 36,404
  • 64
  • 191
  • 318

1 Answers1

0

The camera application on many devices has a defect where it will only properly display in landscape mode, locking the display to landscape mode fixes this but has other problems (like forcing you to manage the layout)

Stackflow Discussion 1

Stackflow Discussion 2

Etc ...

Some devices+sdk versions work in portrait as per the doc's and samples around the web, some don't I have just come to expect they won't and implemented the landscape only route, a bit of a pain but it works.

Community
  • 1
  • 1
Idistic
  • 6,281
  • 2
  • 28
  • 38