QML切换多个摄像头

来源:互联网 发布:中国移动4g网络类型 编辑:程序博客网 时间:2024/06/06 02:45

效果(CSDN图片大小最大2M限制,所以剪辑了一下才能看效果):

图中是做了两个摄像头的切换,多个摄像头一样的原理。



摄像头选择的核心代码,利用改变deviceId来切换摄像头:

    ListView {        anchors.fill: parent        model: QtMultimedia.availableCameras        delegate: Button {            text: modelData.displayName            onClicked:  {                onClicked: camera.deviceId = modelData.deviceId            }        }    }


摄像头显示代码:

import QtQuick 2.5import QtQuick.Controls 1.4import QtMultimedia 5.5Item {    id: cameraItem    property alias name : camera.displayName    property alias deviceId : camera.deviceId    property alias rotation : videoOut.rotation    Item {        anchors.fill: parent        Camera {            id: camera            imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceAuto            exposure {                exposureCompensation: -1.0                exposureMode: Camera.ExposurePortrait            }            flash.mode: Camera.FlashRedEyeReduction            imageCapture {                onImageCaptured: {                    photoPreview.source = preview  // Show the preview in an Image                }            }        }        VideoOutput {            id:videoOut            source: camera            anchors.fill: parent            autoOrientation:true;            focus : visible // to receive focus and capture key events when visible        }        Image {            id: photoPreview        }    }}