android camera portrait orientation

2019-01-22 23:19发布

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

3条回答
姐就是有狂的资本
2楼-- · 2019-01-22 23:27

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楼-- · 2019-01-22 23:33

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;

}
查看更多
霸刀☆藐视天下
4楼-- · 2019-01-22 23:47

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.

查看更多
登录 后发表回答