本帖最后由 一路向北lm 于 2018-12-21 21:35 编辑
1.通过lable方式打开图片。代码如下:void MainWindow::on_pushButton_clicked()
{
Mat srcImage,gray_image,srcImage1;
QString Fileadd = QFileDialog::getOpenFileName(this,"get file");
if(Fileadd.isEmpty())
{
QMessageBox::information(this,"警告","没有选择文件");
return ;
}
//ui->stackedWidget->currentIndex();
srcImage = imread(Fileadd.toLatin1().data()); //读取图片
cvtColor(srcImage,srcImage1,COLOR_BGR2RGB); // 图像格式转换
QImage disImage = QImage((const unsigned char*)(srcImage1.data),srcImage1.cols,srcImage1.rows,QImage::Format_RGB888);
ui->label->setPixmap(QPixmap::fromImage(disImage.scaled(ui->label->size(), Qt::KeepAspectRatio)));
}
|