qt生成圆形头像
程序员文章站
2024-01-02 11:18:10
...
废话不说,直接贴代码
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;
}