根据视频数据的宽高,等比例显示在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();
}