废话不说,直接贴代码
QPixmap HeadPortraitUtil::pixmapToRound(const QPixmap &srcPixmap, int radius)
{
if (srcPixmap.isNull()) {
return QPixmap();
}
QSize size(2 * radius, 2 * radius);
QBitmap mask(size);
QPainter painter(&mask);
//painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.fillRect(0, 0, size.width(), size.height(), Qt::white);
painter.setBrush(QColor(0, 0, 0));
painter.drawRoundedRect(0, 0, size.width(), size.height(), 999, 999);
QPixmap image = srcPixmap.scaled(size);
image.setMask(mask);
return image;
}