Qt5摄像头截图

                    Qt5中去除了Phono,却而代之的是QtMultimedia,模块提供了许多与多媒体有关的类。ide

                    今天主要使用QCamera类来打开设备和显示图像,以及截图。函数

                    1.QCamera类这个QCamera类提供了接口系统相机设备QCamera可以被用和QVideoWidget一块儿取景器显示,和QMediaRecorder一块儿视频录制,和QCameraImageCapture 一块儿进行图像采起。ui

                    三种模式:1只是用来显示2静态图片捕获3视频捕获code

                   

p_camera = new QCamera;//启用系统默认的摄像头
p_ciCapture = new QCameraImageCapture(p_camera);//用摄像头初始化一个QCameraImageCapture用来截图
p_camera->setCaptureMode(QCamera::CaptureStillImage);//设置摄像头的模式,能够抓取静态图像
p_camera->setViewfinder(ui->widget);//设置显示的窗体
p_camera->start();//摄像头启动



//能够截图则截图
if (p_ciCapture->isReadyForCapture()) {
    p_ciCapture->capture();
}

//截图后QCameraImageCapture发出下面这个信号,与一个槽相连显示图片
imageCaptured(int,QImage)

//显示截图的图片的槽函数
QImage scaledImage = image.scaled(ui->widget->size(),
                                      Qt::KeepAspectRatio,
                                      Qt::SmoothTransformation);
ui->label->setPixmap(QPixmap::fromImage(scaledImage));

不过截取的图片可能出现断裂的状况,多是底层的问题。

orm

相关文章
相关标签/搜索