Qt的QCamera Viewfinder的C ++方向

时间:2018-06-28 06:54:13

标签: c++ ios qt qt5 qcamera

我对Qt的QCamera Viewfinder有问题。当我启动应用程序时,在取景器中看到的屏幕旋转了270°。 当我将手机旋转到风景时,取景器将其旋转180度。 我尝试了以下Qt版本: 5.9.4和 5.10.4和 5.11.1

我尝试了以下iOS版本: 10.x和 11.4(当前)

我的XCode版本是: 9.4.1(9F2000)

这是我的源代码:

MainWindow::MainWindow(QWidget* parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , camera(nullptr)
    , camList(QCameraInfo::availableCameras(QCamera::Position::BackFace))
    , imgCapture(nullptr)
{
    ui->setupUi(this);

    QObject::connect(ui->captureButton, &QPushButton::clicked, this, &MainWindow::OnCaptureButtonClicked);
    QObject::connect(ui->cameraComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &MainWindow::OnCameraChanged);
    QObject::connect(ui->zoomSlider, &QSlider::valueChanged, this, &MainWindow::OnZoomChanged);

    for (QList<QCameraInfo>::iterator it = camList.begin(); it != camList.end(); ++it)
    {
        ui->cameraComboBox->addItem(it->description());
    }
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::OnCameraChanged(int index)
{
    if (this->camera != nullptr)
    {
        this->camera->stop();
        delete this->camera;
    }

    this->camera = new QCamera(camList.at(index), this);
    this->focus = this->camera->focus();
    this->maximumOptZoom = this->focus->maximumOpticalZoom();
    ui->zoomSlider->setMaximum(this->maximumOptZoom * this->focus->maximumDigitalZoom() * 10);

    this->camera->setViewfinder(ui->viewfinder);
    this->camera->setCaptureMode(QCamera::CaptureStillImage);
    this->camera->start();
}

void MainWindow::OnCaptureButtonClicked()
{
    this->imgCapture = new QCameraImageCapture(this->camera, this);
    QObject::connect(this->imgCapture, &QCameraImageCapture::imageCaptured, this, &MainWindow::OnImageCapured);
    this->camera->searchAndLock();
    this->imgCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
    this->imgCapture->capture();
}

void MainWindow::OnImageCapured(int, const QImage& image)
{
    QPixmap pix = QPixmap::fromImage(image).scaled(ui->previewLabel->size(), Qt::KeepAspectRatio);
    ui->previewLabel->setPixmap(pix);
    this->camera->unlock();
    this->imgCapture->deleteLater();
}

你知道这奇怪的原因是什么吗?

0 个答案:

没有答案