mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-19 18:35:07 +03:00
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:
parent
2dc85eabe1
commit
0f292e7821
5 changed files with 47 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue