你在叫错树,这应该可以,使用来自 Phonon::VideoWidget 的 snapshot() 函数创建一个 QImage
编辑
我已经进一步调查了这个问题。快照功能甚至没有实现。这是 phonon src videowidget.cpp 中的实现:
QImage VideoWidget::snapshot() const {
P_D(const VideoWidget);
ConstIface<IFACES4> iface(d);
if(iface) return iface->snapshot();
return QImage(); // TODO not implemented in VideoInterface
}
IFACES4 指的是 VideoWidgetInterface44,它为声子 4.4 定义如下(来自 videowidgetinterface.h):
class VideoWidgetInterface
{
public:
virtual ~VideoWidgetInterface() {}
virtual Phonon::VideoWidget::AspectRatio aspectRatio() const = 0;
virtual void setAspectRatio(Phonon::VideoWidget::AspectRatio) = 0;
virtual qreal brightness() const = 0;
virtual void setBrightness(qreal) = 0;
virtual Phonon::VideoWidget::ScaleMode scaleMode() const = 0;
virtual void setScaleMode(Phonon::VideoWidget::ScaleMode) = 0;
virtual qreal contrast() const = 0;
virtual void setContrast(qreal) = 0;
virtual qreal hue() const = 0;
virtual void setHue(qreal) = 0;
virtual qreal saturation() const = 0;
virtual void setSaturation(qreal) = 0;
virtual QWidget *widget() = 0;
virtual int overlayCapabilities() const = 0;
virtual bool createOverlay(QWidget *widget, int type) = 0;
};
class VideoWidgetInterface44 : public VideoWidgetInterface
{
public:
virtual QImage snapshot() const = 0;
};
}
#ifdef PHONON_BACKEND_VERSION_4_4
namespace Phonon { typedef VideoWidgetInterface44 VideoWidgetInterfaceLatest; }
#else
namespace Phonon { typedef VideoWidgetInterface VideoWidgetInterfaceLatest; }
#endif
我还研究了 gstreamer 和 vlc 后端的实现。它们还不支持 phonon 4.4 的快照功能。所以暂时我会寻找其他方法来创建快照。