#include "CAM.h" #include "ui_CAM.h" #include #include #include #include #include #include "camera.h" CAM::CAM(QWidget *parent) : QWidget(parent) , ui(new Ui::CAM) { ui->setupUi(this); /* 摄像头 */ camera = new Camera(this); scanCameraDevice(); /* 信号连接槽 */ connect(camera, SIGNAL(readyImage(QImage)), this, SLOT(showImage(QImage))); connect(ui->cam_traBut,SIGNAL(clicked(bool)), camera, SLOT(cameraProcess(bool)));//开启摄像头 connect(ui->cam_playBut, SIGNAL(clicked()), this, SLOT(saveImageToLocal())); } CAM::~CAM() { delete ui; } void CAM::scanCameraDevice() { /* QFile文件指向/dev/video1 */ QFile file("/dev/video1"); file.setFileName("/dev/video1"); if (file.exists()) { qDebug()<<"camera success" ; camera->selectCameraDevice(1);//video1 } else { qDebug()<<"camera cannot finded" ; } } void CAM::showImage(const QImage &image) { /* 显示图像 */ ui->displayLabel->setPixmap(QPixmap::fromImage(image)); saveImage = image; /* 判断图像是否为空,空则设置拍照按钮不可用 */ if (!saveImage.isNull()) ui->cam_playBut->setEnabled(true); else ui->cam_playBut->setEnabled(false); } void CAM::saveImageToLocal() { /* 判断图像是否为空 */ if (!saveImage.isNull()) { QString fileName = QCoreApplication::applicationDirPath() + "/test.png"; qDebug()<<"正在保存"<cam_albumBut->setPixmap(QPixmap::fromImage(QImage(fileName))); qDebug()<<"保存完成!"<