美文网首页
QT QImage 添加圆角

QT QImage 添加圆角

作者: 严青_ | 来源:发表于2021-06-10 10:32 被阅读0次
    void QMemberData::resizeImage(QImage * image)
    {
        if (image != nullptr) {
          //按比例缩放
            QSize size  = {48,48};
            *image = image->scaled (size.width (),size.height (),Qt::KeepAspectRatio);
            //变为圆角
            QPixmap pixmOld =  QPixmap::fromImage (*image);
            QPixmap pixmap(size);
            pixmap.fill (Qt::transparent);
            QPainter painter(&pixmap);
            painter.setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
            QPainterPath path;
            QRect rect = QRect(QPoint(0,0),size);
            path.addRoundedRect (rect,24,24);
            painter.setClipPath (path);
            painter.drawPixmap (rect,pixmOld);
            *image = pixmap.toImage ();
         }
    }
    
    image.png

    相关文章

      网友评论

          本文标题:QT QImage 添加圆角

          本文链接:https://www.haomeiwen.com/subject/lmjueltx.html