:11.288KB : :1 :2022-10-11 15:54:09
Qt调用摄像头拍照(截图)如果开发者对于本文件有需要的可以参考。
#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
02-05无视DPI的截图录屏GIF开源
01-25鼠标选区截图简单版本,无视DPI缩放
10-19Qt调用Basler相机取图
10-15QT调用vector的CAN设备代码
10-09QT的截图工具软件代码
10-05QT实现屏幕截图
09-19QT实现USB摄像拍照
09-18Qt实现 屏幕截图
08-30杨辉三角doc(截图+代码)
10-04ppt幻灯片屏幕截图的图片导入方法
08-29word屏幕截图方法图解
11-25做word整页截图的方法
11-20在Excel表格使用照相机功能进行截图
11-17WORD文档自带截图工具使用方法
11-06wps截图的方法
10-30PPT文件截图并插入的教程