我正在使用Qt Qcamera
在Windows Surface Pro平板电脑上拍摄图像。我写了这小段代码来检查QCamera的功能,但在拍摄图像后,保存的图像分辨率非常低,即640*360,尽管surface pro的后置摄像头支持1280*720。即使是支持解析的QList也总是返回空。我到处找,但找不到可能的解决方案,有人能帮忙吗?
这是我正在使用的代码:
#include "camera.h"
#include <QCamera>
#include <QCameraImageCapture>
#include <QCameraViewfinder>
#include <QDebug>
#include<QMultimedia>
Camera::Camera(QWidget *parent) :
QWidget(parent)
{
QByteArray cameraDevice;
int count = QCamera::availableDevices().count();
int cameraId = 1;
QList<QByteArray> cameradev = QCamera::availableDevices();
QByteArray camdevice = cameradev[cameraId];
QCamera *camera = new QCamera(camdevice);
QString description = camera->deviceDescription(camdevice);
qDebug() <<"Device Name"<< description;
QCameraViewfinder *viewfinder = new QCameraViewfinder();
viewfinder->showMaximized();
camera->setViewfinder(viewfinder);
QCameraImageCapture *imageCapture = new QCameraImageCapture(camera);
//camera->setCaptureMode(QCamera::CaptureStillImage);
camera->start();
QList<QSize> resolutions = imageCapture->supportedResolutions();//returns always empty
QImageEncoderSettings imageSettings;
imageSettings.setCodec("image/jpeg");
imageSettings.setResolution(1280, 720);
imageCapture->setEncodingSettings(imageSettings);
imageCapture->capture("D:/1.jpg");
camera->searchAndLock();
camera->unlock();
qDebug() << camera->error();
}
问题似乎出在Qt版本上,这个问题在Qt 5.5及更高版本中得到了修复,可以获得相机的所有支持分辨率。