From 0f292e7821b809df77de443dd30148a609cc4f49 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Wed, 5 Feb 2020 16:02:05 +0000 Subject: qcam: Provide save image functionality Implement a save image button on the toolbar which will take a current viewfinder image and present the user with a QFileDialog to allow them to choose where to save the image. Utilise the QImageWriter to perform the output task. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/qcam/main_window.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/qcam/main_window.cpp') diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index f76890e7..29eaba84 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -12,7 +12,10 @@ #include #include +#include #include +#include +#include #include #include #include @@ -88,6 +91,9 @@ int MainWindow::createToolbars() action = toolbar_->addAction(QIcon(":stop-circle.svg"), "stop"); connect(action, &QAction::triggered, this, &MainWindow::stopCapture); + action = toolbar_->addAction(QIcon(":save.svg"), "saveAs"); + connect(action, &QAction::triggered, this, &MainWindow::saveImageAs); + return 0; } @@ -339,6 +345,22 @@ void MainWindow::stopCapture() setWindowTitle(title_); } +void MainWindow::saveImageAs() +{ + QImage image = viewfinder_->getCurrentImage(); + + QString filename = QFileDialog::getSaveFileName(this, "Save Image", "", + "Image Files (*.png *.jpg *.jpeg)"); + + std::cout << "Save image to " << filename.toStdString() << std::endl; + + if (filename.isEmpty()) + return; + + QImageWriter writer(filename); + writer.write(image); +} + void MainWindow::requestComplete(Request *request) { if (request->status() == Request::RequestCancelled) -- cgit v1.2.1