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
网友评论