QWidget和xvimagesink问题!

发布于 2024-10-10 09:47:14 字数 901 浏览 1 评论 0原文

我需要一些帮助! 在 qt 应用程序中我有一个中央小部件。在这个中央小部件中,我有一个 QLabel 和另一个 QWidget 。现在,在 gstreamer 的帮助下,我可以从网络摄像头获取视频并通过第二个小部件显示它。现在的问题是我想截取这个小部件的屏幕截图并将其放在标签上。但我使用的方法只给出了一个空白屏幕。

我尝试了这个:

QPixmap wpix = QPixmap::grabWidget(ui->videoWidget,0,0,640,480);
ui->label->setPixmap(wpix);

和这个:

QPixmap  wpix=QPixmap(ui->videoWidget->size());
wpix.fill(Qt::transparent);
ui->videoWidget->render(&wpix,QPoint(0,0),QRect(0,0,640,480),QWidget::DrawWindowBackground | QWidget::DrawChildren);

唯一有效的是使用grabWindow,但这里还有另一件事:

grabWindow() 函数从屏幕而不是窗口抓取像素,即,如果有另一个窗口部分或完全覆盖您抓取的窗口,您也会从上面的窗口获取像素。

现在grabWindow()因为这个效果就没用了,上面的2个方法也不想工作了!

有人可以告诉我问题是什么吗?可能是因为我将 videoWidget 设置为 nativeWindow (如果我不设置它,我的视频流将不会显示)?

请帮忙!如果您需要更多信息,请告诉我!请原谅我糟糕的英语!

I need some help!
In qt app I have a central widget. In this central widget I have a QLabel ,and another QWidget. Now with the help of gstreamer I can get the video from my webcam and show it via the second widget. Now the problem is that I want to take a screenshot of this widget and put it on the label. But the methods which I used only gave a blank screen.

I tried this :

QPixmap wpix = QPixmap::grabWidget(ui->videoWidget,0,0,640,480);
ui->label->setPixmap(wpix);

and this :

QPixmap  wpix=QPixmap(ui->videoWidget->size());
wpix.fill(Qt::transparent);
ui->videoWidget->render(&wpix,QPoint(0,0),QRect(0,0,640,480),QWidget::DrawWindowBackground | QWidget::DrawChildren);

The only thing that works is to use grabWindow but here another thing:

The grabWindow() function grabs pixels from the screen, not from the window, i.e. if there >is another window partially or entirely over the one you grab, you get pixels from the >overlying window, too.

Now the grabWindow() is no use because of this effect, and the above 2 methods don't want to work!

Can someone please tell me what is the problem.Might it be the fact that I set the videoWidget to be a nativeWindow (if I don't set it my video stream would not be shown)?

Please help! If you need more info let me know! And please excuse my bad english!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢华的一滴泪 2024-10-17 09:47:14
#include "ksmile.h"  
#include "ui_ksmile.h"  
#include <gst/interfaces/xoverlay.h>  
#include <iostream>  

KSmile::KSmile(QWidget *parent) :QMainWindow(parent),ui(new Ui::KSmile)  
{  
    QPalette p(palette()); 
    ui->setupUi(this); 


    // Set background colour to black
    p.setColor(QPalette::Background, Qt::black);
    ui->videoWidget->setPalette(p);
    ui->videoWidget->setGeometry(0,0,640,480);
    ui->videoWidget->setAttribute(Qt::WA_NativeWindow,true);
    ui->videoWidget->show();
    ui->videoWidget->activateWindow();
    QObject::connect(&iTimer, SIGNAL(timeout()), this, SLOT(timerDone()) );
    iTimer.start(500);
}  

void KSmile::startWebCam(int argc, char *argv[])    
{     
     vs_WebCam = new VideoStream(argc,argv);   
     vs_WebCam->vs_initWebCam();   
     gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(vs_WebCam->vs_getVideoSink()),ui->videoWidget->winId());     
     vs_WebCam->vs_playWebCam();     
     vs_WebCam->vs_setBrightness(0);    
     vs_WebCam->vs_setContrast(0);  
     vs_WebCam->vs_setHue(0);  
     vs_WebCam->vs_setSaturation(0);  

}  
void KSmile::timerDone()  
{  
    std::cout << "In timer done " << std::endl;   
    QPixmap  wpix=QPixmap(ui->videoWidget->size());  
     wpix.fill(Qt::transparent)  
     ui->videoWidget->render(&wpix,QPoint(0,0),QRect(0,0,640,480),QWidget::DrawWindowBackground |   QWidget::DrawChildren);    
     ui->label->setPixmap(wpix);  
    /**  
     wpix = QPixmap::grabWindow(ui->videoWidget,0,0,640,480);  
     ui->label->setPixmap(wpix); */  


}  

KSmile::~KSmile()  
{  
    delete ui;  
}  
#include "ksmile.h"  
#include "ui_ksmile.h"  
#include <gst/interfaces/xoverlay.h>  
#include <iostream>  

KSmile::KSmile(QWidget *parent) :QMainWindow(parent),ui(new Ui::KSmile)  
{  
    QPalette p(palette()); 
    ui->setupUi(this); 


    // Set background colour to black
    p.setColor(QPalette::Background, Qt::black);
    ui->videoWidget->setPalette(p);
    ui->videoWidget->setGeometry(0,0,640,480);
    ui->videoWidget->setAttribute(Qt::WA_NativeWindow,true);
    ui->videoWidget->show();
    ui->videoWidget->activateWindow();
    QObject::connect(&iTimer, SIGNAL(timeout()), this, SLOT(timerDone()) );
    iTimer.start(500);
}  

void KSmile::startWebCam(int argc, char *argv[])    
{     
     vs_WebCam = new VideoStream(argc,argv);   
     vs_WebCam->vs_initWebCam();   
     gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(vs_WebCam->vs_getVideoSink()),ui->videoWidget->winId());     
     vs_WebCam->vs_playWebCam();     
     vs_WebCam->vs_setBrightness(0);    
     vs_WebCam->vs_setContrast(0);  
     vs_WebCam->vs_setHue(0);  
     vs_WebCam->vs_setSaturation(0);  

}  
void KSmile::timerDone()  
{  
    std::cout << "In timer done " << std::endl;   
    QPixmap  wpix=QPixmap(ui->videoWidget->size());  
     wpix.fill(Qt::transparent)  
     ui->videoWidget->render(&wpix,QPoint(0,0),QRect(0,0,640,480),QWidget::DrawWindowBackground |   QWidget::DrawChildren);    
     ui->label->setPixmap(wpix);  
    /**  
     wpix = QPixmap::grabWindow(ui->videoWidget,0,0,640,480);  
     ui->label->setPixmap(wpix); */  


}  

KSmile::~KSmile()  
{  
    delete ui;  
}  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文