Android Camera in Portrait on SurfaceView

前端 未结 6 2075
孤城傲影
孤城傲影 2020-12-01 09:06

I tried several things to try to get the camera preview to show up in portrait on a SurfaceView. Nothing worked. I am testing on a Droid that has 2.0.1. I tr

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 09:46

    i have a working solution for portrait mode working in 2.1 (tested on Desire) maybe less.

    Activity screen orientation is set to portrait. (android:screenOrientation="portrait")

    the camera parameters:

    Camera.Parameters p = mCamera.getParameters();

     p.set("jpeg-quality", 100);
     p.set("orientation", "landscape");
     p.set("rotation", 90);
     p.setPictureFormat(PixelFormat.JPEG);
     p.setPreviewSize(h, w);// here w h are reversed
     mCamera.setParameters(p);
    

    and the image will be portrait.

    SurfaceHolder you use for camera must be at a size compatible with phone preview size usualy screen resolution.

    Funny on Desire 2.2 is not working... Here is the fix:

       At surfaceCreated(..) or when you have this line
    camera = Camera.open();
           add
    camera.setDisplayOrientation(90);//only 2.2>
    
    Camera.Parameters p = camera.getParameters();
        p.set("jpeg-quality", 100);
    p.setRotation(90);
    p.setPictureFormat(PixelFormat.JPEG);
    p.setPreviewSize(h, w);
    camera.setParameters(p);
    

提交回复
热议问题