QML Camera设置分辨率

QML Camera设置分辨率方式

直接上测试代码,该代码在Qt5.5.1版本测试通过。

示例代码的主要功能是:点击窗口就可以截取摄像头中图片,在控制台上打印支持的分辨率。

import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Layouts 1.2
import QtQuick.Controls 1.4
import QtMultimedia 5.5

Item {
    width: 640
    height: 360

    Camera {
        id: camera

        // 本函数用于打印支持的分辨率
        function getSupportResulution()
        {
            var res = camera.supportedViewfinderResolutions()

            for(var index in res){
                console.info(index+":"+res[index].width+"====="+res[index].height);
            }
        }

        // 这里是关键
        captureMode: Camera.CaptureViewfinder;
        // 设置自己想要的分辨率(上面分辨率中的一个)
        viewfinder.resolution: Qt.size(160,120);

        // 下面的代码是套话
        imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash

        exposure {
            exposureCompensation: -1.0
            exposureMode: Camera.ExposurePortrait
        }

        flash.mode: Camera.FlashRedEyeReduction

        imageCapture {
            onImageCaptured: {
                photoPreview.source = preview  // Show the preview in an Image
                // 调用函数,在控制台上看支持的分辨率
                camera.getSupportResulution();
            }
        }
    }

    VideoOutput {
        source: camera
        anchors.fill: parent
        focus : visible // to receive focus and capture key events when visible
    }

    Image {
        id: photoPreview
    }

    // 点击窗口就会截取一帧画面
    MouseArea{
        anchors.fill: parent;
        onClicked: {
            var imgPath = "C:\\test";
            camera.imageCapture.captureToLocation(imgPath)
        }
    }
}

设置分辨率是工作中遇到的一个问题,根据参考文档的思路,但是这个参考文档等示例没有执行成功,后来在qt帮助文档中找到示例和思路。

参考文档:

qt帮助 -> Camera -> Qt Multimedia 5.5

https://stackoverflow.com/questions/40757220/qml-change-the-resolution-before-camera-image-capture

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值