做开发的时候,需要在lcd制定区域播放视频,播放器是gstreamer,用到了overlaysink组件,但是这个组件会吧视频之外的区域渲染黑,此时板式显示不出来。后来经过研究,用color_key可以完美解决这个问题。下面直接上代码:#include "mainwindow.h"
#include "ui_mainwindow.h"
#include #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
struct mxcfb_gbl_alpha gbl_alpha;
struct mxcfb_color_key key;
int ret; ui->setupUi(this); setCursor(QCursor(Qt::BlankCursor)); QWidget *widget;
widget = new QWidget(this);
widget->setGeometry(0, 0, 800, 600); QPalette palette;
palette.setColor(QPalette::Background, QColor(0,0,0));
widget->setPalette(palette);
widget->setAutoFillBackground(true);
widget->show(); int fd;
if ((fd = open("/dev/fb0", O_RDWR, 0)) < 0) {
fprintf(stderr, "Unable to open %s
", "/dev/fb0");
} gbl_alpha.enable = 1;
gbl_alpha.alpha = 255; // BG opaque ret = ioctl(fd, MXCFB_SET_GBL_ALPHA, &gbl_alpha);
if (ret)
qDebug() << "set Global Alpha error";
key.enable = 1;
key.color_key = 0x00000000; // Black
ret = ioctl(fd, MXCFB_SET_CLR_KEY, &key);
if (ret)
qDebug() << "set Color key error"; //std::close(fd);
}MainWindow::~MainWindow()
{
delete ui;
}
此时,板式可以随意显示,板式中的黑 {MOD}会被视频透出来。