android Camera 录像时旋转角度

录像保存时,旋转角度要与所拍录像时的角度保持一致,否则,看起来就会出现角度不度,巅倒等问题。

一般在开始录像之前会先去初始化录像

initializeRecorder 中会去读取当前的录像或拍照的旋转角度,并跟据当前的角度来选择一个角度写到所拍

照片或者视频的 exif 信息中去。

        // See android.hardware.Camera.Parameters.setRotation for
        // documentation.
        // Note that mOrientation here is the device orientation, which is the opposite of
        // what activity.getWindowManager().getDefaultDisplay().getRotation() would return,
        // which is the orientation the graphics need to rotate in order to render correctly.
        int rotation = 0;
        if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
            CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
            if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
                rotation = (info.orientation - mOrientation + 360) % 360;
            } else {  // back-facing camera
                rotation = (info.orientation + mOrientation) % 360;
            }
        } else {
        	//Get the right original orientation
        	CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
            rotation = info.orientation;
        }
//        mMediaRecorder.setOrientationHint(rotation);

		if (mCameraId == CameraInfo.CAMERA_FACING_FRONT) {
			if (rotation == 270 || rotation == 90 || rotation == 180) {
				mMediaRecorder.setOrientationHint(180);
			} else {
				mMediaRecorder.setOrientationHint(0);
			}
		} else {
			if (rotation == 180){
				mMediaRecorder.setOrientationHint(180);
			}else{
				mMediaRecorder.setOrientationHint(0);
			}
		}



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值