QString path = QFileDialog::getOpenFileName(this, tr("选择视频"), ".", tr("Image Files(*.jpg *.png)")); QImage* img=new QImage; QImage* scaledimg=new QImage;//分别保存原图和缩放之后的图片 if(! ( img->load(path) ) ) //加载图像 { QMessageBox::information(this, tr("打开图像失败"), tr("打开图像失败!")); delete img; return; } int Owidth=img->width(),Oheight=img->height(); int Fwidth,Fheight; //缩放后的图片大小 ui->label->setGeometry(100,100,400,300); int Mul; //记录图片与label大小的比例,用于缩放图片 if(Owidth/400>=Oheight/300) Mul=Owidth/400; else Mul=Oheight/300; Fwidth=Owidth/Mul; Fheight=Oheight/Mul; *scaledimg=img->scaled(Fwidth,Fheight,Qt::KeepAspectRatio); //ui->label_text->setText(QString("width: ")+StrWidth.setNum(Fwidth) // +QString("\nheight: ")+StrHeigth.setNum(Fheight)); ui->label->setPixmap(QPixmap::fromImage(*scaledimg));