QCamera本身是不负责显示显示图片的,需要通过setViewfinder设置接收视频帧的对象,setViewfinder支持三种格式,为了尽可能的拿到真是数据,我采用了继承QAbstractVideoSurface的方式
CBaseCameraSurface.h
#ifndef CBASECAMERA_H
#define CBASECAMERA_H
#include
#include
#include
class CBaseCameraSurface : public QAbstractVideoSurface
{
Q_OBJECT
public:
explicit CBaseCameraSurface(QObject *parent = nullptr);
~CBaseCameraSurface();
virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const override;
virtual bool present(const QVideoFrame &frame) override;
virtual bool start(const QVideoSurfaceFormat &format) override;
virtual void stop() override;
virtual QList supportedPixelFormats(QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const override;
signals:
void frameAvailable(QVideoFrame& frame);
public slots:
};
#endif // CBASECAMERA_H
CBaseCameraSurface.cpp
#include "CBaseCameraSurface.h"
#include
CBaseCameraSurface::CBaseCameraSurface(QObject *parent) : QAbstractVideoSurface(parent)
{
}
CBaseCameraSurface::~CBaseCameraSurface(){}
bool CBaseCameraSurface::isFormatSupported(const QVideoSurfaceFormat &format) const{
return QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat()) != QImage::Format_Invalid;
}
QList CBaseCameraSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
{
if(handleType == QAbstractVideoBuffer::NoHandle){
return QList() |