zoukankan      html  css  js  c++  java
  • Qt图片按原比例缩放

    1.选择图片

    QString strFilePath = QFileDialog::getOpenFileName(this, tr("Select file"), QStandardPaths::standardLocations(QStandardPaths::PicturesLocation), "*.png *.jpg");
    if (strFilePath.isEmpty())
    {
      return;
    }

    2.图片合法性校验

    复制代码
    QImageReader imgReader;
    imgReader.setFileName(strFilePath);
    if (!imgReader.canRead())
    {
        QMessageBox::information(0, "", QObject::tr("The image data is corrupt, Please select a valid one!"));
        return;
    }
    复制代码

    3.原图比例缩放

    复制代码
    int nThumbnailWidth  = 80;
    int nThumbnailHeight = 80;
    QLable *pThumbLab = new QLabel(this);
    pThumbLab->setFixedSize(nThumbnailWidth, nThumbnailHeight);
    
    QSize sizeImage = imgReader.size();
    QPixmap pixThumb(mstrPicPath);
    if (sizeImage.width() > nThumbnailWidth || sizeImage.height() > nThumbnailHeight)
    {
        if (sizeImage.width() > sizeImage.height())
        {
            pixThumb = pixThumb.scaledToWidth(nThumbnailWidth, Qt::SmoothTransformation);
        }
        else
        {
            pixThumb = pixThumb.scaledToHeight(nThumbnailHeight, Qt::SmoothTransformation);
        }
        pThumbLab->setFixedSize(pixThumb.size());
    }
    else
    {
        pThumbLab->setFixedSize(sizeImage);
    }
    pThumbLab->setPixmap(pixThumb);
    复制代码

    https://www.cnblogs.com/sz-leez/p/7120721.html

  • 相关阅读:
    致橡树——舒婷
    MPU6050
    Android自动折行TextView Group
    基于LRU Cache的简单缓存
    如果不能给心以翅膀,她如何飞翔
    ubuntu手机识别
    Webkit JNI
    scrapy入门
    Webkit二:RenderTree 创建
    Webkit一:Dom转码和解析
  • 原文地址:https://www.cnblogs.com/findumars/p/5164267.html
Copyright © 2011-2022 走看看