Try something like this for a slow approach
for (int x = 0; x < oldImage.width(); ++x) {
for (int y = 0; y < oldImage.width(); ++y) {
if (polygon.containsPoint(p, Qt::OddEvenFill)) {
QRgb color = oldImage.pixel(p);
newImage.setPixel(p, color);
}
}
}
for (int x = 0; x < oldImage.width(); ++x) {
for (int y = 0; y < oldImage.width(); ++y) {
QPoint p(x, y);
if (polygon.containsPoint(p, Qt::OddEvenFill)) {
QRgb color = oldImage.pixel(p);
newImage.setPixel(p, color);
}
}
}
To copy to clipboard, switch view to plain text mode
(Untested code)
You should investigate ways to use the image composition modes to draw a filled version of your polygon over a copy of the original leaving only the intersection. This would be much faster.
Bookmarks