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 <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
@@ -12,7 +12,10 @@
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QCoreApplication>
|
||||
#include <QFileDialog>
|
||||
#include <QIcon>
|
||||
#include <QImage>
|
||||
#include <QImageWriter>
|
||||
#include <QInputDialog>
|
||||
#include <QTimer>
|
||||
#include <QToolBar>
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user