QPixmap PixmapToRound(const QPixmap& src, int diameter/*直径*/)
{
if (src.isNull())
{
return QPixmap();
}
QSize size(diameter, diameter);
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(), 99, 99);
QPixmap image = src.scaled(size);
image.setMask(mask);
return image;
}
QT 将pixmap绘制成圆形
最新推荐文章于 2024-05-17 19:42:03 发布