qt QCamera摄像头的简单实用

qt QCamera摄像头的简单实用_第1张图片

.h

    QCamera *camera;//摄像头
    QCameraViewfinder * viewfinder;//摄像头取景器部件
    QCameraImageCapture * imageCapture;//截图部件


.cpp

    camera=new QCamera;//摄像头
    viewfinder=new QCameraViewfinder(ui->label_2);
    imageCapture=new QCameraImageCapture(camera);//截图部件
    camera->setViewfinder(viewfinder);

    QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(ShowTheCapture()));
    QObject::connect(ui->SaveButton,SIGNAL(clicked()),this,SLOT(SavePicture()));
    QObject::connect(imageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(displayImage(int,QImage)));
    imageCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
    camera->setCaptureMode(QCamera::CaptureVideo);
    camera->setViewfinder(viewfinder);
    camera->start();

最基本的功能就已经实现

 

2. 遍历当前所有摄像头

 QList cameras = QCameraInfo::availableCameras();  
  foreach (const QCameraInfo &cameraInfo, cameras) {            
      QString str = cameraInfo.description();                   
      QString ss = cameraInfo.deviceName();                     
      if (cameraInfo.deviceName() == "yourcamera") 
           //判断你需要的摄像头来进行使用               
                                                                
          camera = new QCamera(cameraInfo);                     
                                                                
          camera->start(); //启动摄像头                              
  }       

                                                      

你可能感兴趣的:(Qt)