How to set image resolution with QCamera in Qt 5.3?

2.9k views Asked by At

I am working on Qt Qcamera to capture images, on Windows Surface Pro tablet. I have written this small piece of code to check the QCamera functionaliy, but after capturing the image, the image saved has very low resolution i.e. 640*360, even though the rear camera of surface pro supports 1280*720. Even the QList for supported resolution always returns empty. I looked everywhere but couldn't find a possible solution, can anyone please help?

Here is the code I am using:

#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();    
}
1

There are 1 answers

0
user3807950 On BEST ANSWER

Well it seemed the problem was with Qt version, this problem is fixed in Qt 5.5 version and above and it's possible to get all supported resolutions of a camera.