If you don't have a closed polygon then what defines the region you want to copy?
Here is an example of a faster way to do it:
#include <QtGui>
int main(int argc, char *argv[])
{
// An arbitrary region to cut out
// Let's do it
path.addPolygon(region);
QImage cutout
(source.
size(),
QImage::Format_ARGB32_Premultiplied);
cutout.fill(Qt::transparent);
p.setClipPath(path);
p.drawImage(0, 0, source);
p.end();
l.
setPixmap(QPixmap::fromImage(cutout
));
l.show();
return a.exec();
}
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QImage source("Lenna.png");
// An arbitrary region to cut out
QPolygon region;
region << QPoint(10, 10) << QPoint(100, 200) << QPoint(500, 50);
// Let's do it
QPainterPath path;
path.addPolygon(region);
QImage cutout(source.size(), QImage::Format_ARGB32_Premultiplied);
cutout.fill(Qt::transparent);
QPainter p(&cutout);
p.setClipPath(path);
p.drawImage(0, 0, source);
p.end();
QLabel l;
l.setPixmap(QPixmap::fromImage(cutout));
l.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks