#include "widget.h"
#include <QLayout>
#include <QLabel>
#include <QPushButton>
#include <QFileDialog>
#include <QCamera>
#include <QCameraViewfinder>
#include <QCameraImageCapture>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
setWindowTitle("QCamera");
m_pCamera = new QCamera(this);
m_pViewfinder = new QCameraViewfinder(this);
m_pImageCapture = new QCameraImageCapture(m_pCamera);
QPushButton* button1 = new QPushButton("Capture");
QPushButton* button2 = new QPushButton("Exit");
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(m_pViewfinder);
mainLayout->addWidget(button1);
mainLayout->addWidget(button2);
connect(button1, SIGNAL(clicked()), m_pImageCapture, SLOT(capture()));
connect(button2, SIGNAL(clicked()), this, SLOT(exitBtnResponded()));
connect(m_pImageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(cameraImageCaptured(int,QImage)));
m_pImageCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
m_pCamera->setCaptureMode(QCamera::CaptureStillImage);
m_pCamera->setViewfinder(m_pViewfinder);
m_pCamera->start();
}
Widget::~Widget()
{
delete m_pCamera;
delete m_pViewfinder;
delete m_pImageCapture;
}
void Widget::exitBtnResponded()
{
m_pCamera->stop();
close();
}
void Widget::cameraImageCaptured(int, QImage image)
{
QString savepath = QFileDialog::getSaveFileName(this,"Save Capture","Capture","Image png(*.png);;Image jpg(*.jpg);;Image bmp(*.bmp)");
if(!savepath.isEmpty()){
image.save(savepath);
}
}
QCamera 简单使用
4星 · 超过85%的资源 需积分: 50 58 浏览量
2017-12-08
16:28:03
上传
评论 4
收藏 2KB RAR 举报
决战小树林
- 粉丝: 113
- 资源: 37
最新资源
- Fortran语言教程,详细地介绍了Fortran语言
- (函数)图论中最短路径计算D算法MATLAB源代码,修改网络上D算法的错误,并编写通用的MATLAB函数.rar
- 基于matlab 2Dijkstra最短路径算法的matlab程序,希望对大家有所帮助.zip
- python入门学习,基础语法,用法等.zip
- Swift代码转换指南(Swift Swift Code Convension Guide .)
- Python入门到精通.zip
- 基于QT+C++开发的炫酷九宫格主界面+源码
- python入门代码测试.zip
- 一种基于Python实现中文编码格式转换工具的源码
- 基于matlab dijkstra算法,可以求解图论中的两点间最短路径.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈