一个QDialog里面有个QLabel,QLabel显示摄像机的图片.QLabel显示大小为1920*1080.摄像机大小是1280*720.在不缩放图像的情况下,如何铺满整个QLabel?
解决方法如下:pLabel->setScaledContents(true);
绘制图像代码如下:
if (ipl){
QImage img = QImage((const unsigned char *)(ipl->imageData), ipl->width, ipl->height,
ipl->width*ipl->nChannels, QImage::Format_RGB888);
int nWidth = pLabel->width();
int nHeight = pLabel->height();
pLabel->setPixmap(QPixmap::fromImage(img));
cvReleaseImage(&ipl);
ipl = NULL;
}
环境:
主窗口 resize(1920, 1080);
初始化一个QLabel部件
pLabel = new QLabel(this);
pLabel->resize(1920, 1080);
pLabel->setScaledContents(true);
IplImage *ipl;是从摄像机回调函数出来的RGB 3通道图像。