QT QImage 添加圆角
2021-06-10 本文已影响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