基本信息
源码名称:Qt调用摄像头拍照(截图)
源码大小:0.01M
文件格式:.zip
开发语言:C/C++
更新时间:2021-12-08
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
camera = new QCamera(this);
//viewfinder = new QCameraViewfinder(this);
m_view = new MyView(this);
imageCapture = new QCameraImageCapture(camera);
//ui->ImageView->addWidget(viewfinder);
ui->ImageView->addWidget(m_view);
ui->ImageCapture->setScaledContents(true);
//camera->setViewfinder(viewfinder);
camera->setViewfinder(m_view);
connect(imageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(displayImage(int,QImage)));
connect(ui->buttonCapture, SIGNAL(clicked()), this, SLOT(captureImage()));
connect(ui->buttonSave, SIGNAL(clicked()), this, SLOT(saveImage()));
connect(ui->buttonQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
connect(ui->buttonStop,SIGNAL(clicked()),camera,SLOT(stop()));
connect(ui->buttonStart,SIGNAL(clicked()),camera,SLOT(start()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::captureImage()
{
imageCapture->capture();
}
void MainWindow::displayImage(int , QImage image)
{
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer,"jpg");
ui->ImageCapture->setText(QString::number(ba.size()));
QImage pic;
pic.loadFromData(ba);
ui->ImageCapture->setPixmap(QPixmap::fromImage(pic));
}
void MainWindow::saveImage()
{
QString fileName=QFileDialog::getSaveFileName(this, tr("save file"), QDir::homePath(), tr("jpegfile(*.jpg)"));
if(fileName.isEmpty()) {
return;
}
const QPixmap* pixmap=ui->ImageCapture->pixmap();
if(pixmap) {
pixmap->save(fileName);
}
}
【源码目录】
.
└── untitled
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── myview.cpp
├── myview.h
├── untitled.pro
├── untitled.pro.user
├── untitled.pro.user.22
└── untitled.pro.user.b66346c
1 directory, 10 files