QLabel按比例缩放显示图片,并且读取

其实就是设置了几个属性,QT会自动帮我们缩放,宽高按照等比例缩放,不会出现宽度或者高度被拉伸这种情况,最后还有一个获取图片真实宽高的代码。

    pixmap=QPixmap::fromImage(myImage);
    ui->lbe_image->setPixmap(pixmap.scaled(ui->lbe_image->size(),Qt::KeepAspectRatio,Qt::SmoothTransformation));
    qDebug()<<"QLabel尺寸:["<<ui->lbe_image->width()<<","<<ui->lbe_image->height()<<"]";
    qDebug()<<"图片真实尺寸:["<<ui->lbe_image->pixmap()->width()<<","<<ui->lbe_image->pixmap()->height()<<"]";

猜你喜欢

转载自blog.csdn.net/weixin_42485732/article/details/130858621