如何固定surfaceView中previewDisplay的方向?

问题描述 投票:0回答:0

This is how it is showing

这是代码,我尝试了很多与纵横比和预览大小相关的东西。由于我想处于纵向模式,因此视频已正确保存。

enter code here
 camera?.let {
        val params = it.parameters
        params.set("orientation","portrait")
        params.setRotation(90)
        val surfaceView = binding.surfaceView
        val previewSizes = camera?.parameters?.supportedPreviewSizes

        val surfaceHolder = surfaceView.holder
            camera?.setPreviewDisplay(surfaceHolder)
            camera?.startPreview()
    }

    // Initialize media recorder
    mediaRecorder = MediaRecorder()
    mediaRecorder?.let {
        it.setAudioSource(MediaRecorder.AudioSource.MIC)
        it.setVideoSource(MediaRecorder.VideoSource.CAMERA)
        it.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
        it.setVideoEncoder(MediaRecorder.VideoEncoder.H264)
        it.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
        it.setVideoFrameRate(30)
        it.setVideoEncodingBitRate(10000000)
        it.setOrientationHint(90) // Set the orientation of the video to portrait mode
        it.setPreviewDisplay(surfaceView.holder.surface)
        it.setOutputFile(getOutputFile().path)
    }
android android-camera surfaceview
© www.soinside.com 2019 - 2024. All rights reserved.