android camera portrait orientation

只谈情不闲聊 提交于 2019-12-18 01:05:48

问题


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


回答1:


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.




回答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;
        }



回答3:


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;

}


来源:https://stackoverflow.com/questions/8516118/android-camera-portrait-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!