根据视频数据的宽高,等比例显示在QT得label插件上,下面直接上代码:
void Show(QLabel *label,char *rgbData,int w,int h)
{
QImage img(rgbData,w,h,QImage::Format_RGB888);
QPixmap pixmap = QPixmap::fromImage(img);
int labelwith = label->width();
int labelheight = label->height();
int newWidth = labelwith,newHeight = labelheight;
if(labelwith >= labelheight)
{newHeight = labelheight;
newWidth = newHeight * w/h;
}if(labelwith < labelheight)
{newWidth = labelwith;
newHeight = newWidth * h/w;
}QPixmap fitpixmap = pixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
label->setPixmap(fitpixmap);
//label->setScaledContents(true);
label->setAlignment(Qt::AlignCenter);
label->show();
}
本文介绍了一种方法,用于在QT的Label组件中按原始宽高比显示视频帧。通过使用QImage和QPixmap,代码能够根据Label的尺寸调整视频帧大小,同时保持其宽高比例不变。
893

被折叠的 条评论
为什么被折叠?



