How to round the corners of a QImage?
-
Images are rectangular. It's an array of pixels. Do you mean draw a rounded rectangle and have the corners transparent?
To fill image with transparency see QImage::fill.
To draw a rounded rectangle see QPainter::drawRoundedRect. -
Images are rectangular. It's an array of pixels. Do you mean draw a rounded rectangle and have the corners transparent?
To fill image with transparency see QImage::fill.
To draw a rounded rectangle see QPainter::drawRoundedRect.@Chris-Kawa
I tried this, but the image is still being painted outside the rounded rect:QPainter painter(this); painter.drawImage(0, 0, image().scaled(250, 100, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); painter.drawRoundedRect(QRect(0, 0, 250, 100), 20.0, 20.0);
The image is a rectangle i need to round her borders first, dont?
-
QImage source(256, 256, QImage::Format_ARGB32); source.fill(Qt::blue); QImage dest(source.size(), QImage::Format_ARGB32); dest.fill(Qt::transparent); QPainterPath clipPath; clipPath.addRoundedRect(source.rect().adjusted(10, 10, -10, -10), 20, 20); QPainter p(&dest); p.setClipPath(clipPath); p.drawImage(0, 0, source); p.end(); dest.save("/tmp/test.png");
-
QImage source(256, 256, QImage::Format_ARGB32); source.fill(Qt::blue); QImage dest(source.size(), QImage::Format_ARGB32); dest.fill(Qt::transparent); QPainterPath clipPath; clipPath.addRoundedRect(source.rect().adjusted(10, 10, -10, -10), 20, 20); QPainter p(&dest); p.setClipPath(clipPath); p.drawImage(0, 0, source); p.end(); dest.save("/tmp/test.png");