Android: Camera preview Rotated

2019-08-12 08:52发布

问题:

i am facing a problem in my application, i am using this for the camera preview, but in the camera preview even the person standing vertically is appearing to stand horizontally... , it seems i am missing something in my preview

mSurfaceView = (SurfaceView)findViewById(R.id.surface);
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

plz help me out , thanx

回答1:

Give this a try: http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)

I'm not sure if you are saying that the preview is incorrect, or if the preview looks good and the saved picture is wrong. That link above should fix the preview problem.

If the saved JPEG isn't right try this: http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setRotation(int)

I just copied and pasted both hunks of code, it helped a lot.



回答2:

when you getSupportedPreviewSizes from Camera.Parameters if you see supported previewSize have height <= width , it means that the camera driver does not support previewSize for portrait mode (height > width). you can refer this to get more info