PDA

View Full Version : How to copy sellected ellipse area from image



adamsakli
24th September 2009, 12:01
Hi guys
I'm developing a program for image prosessing. I want to copy selected ellipse area on image. How can i do this. I developed a program which draw an ellipse on image when mouse move.
The problem i want to copy this area. How can i copy? QImage has a copy function but this is for rectangle not ellipse. How can i copy ellipse area. I put image what i did.

Grimlock
24th September 2009, 18:18
Cheat copy a rect and than set every thing outside the ellipse to alpha.

burnttoy
24th September 2009, 22:11
Hiya,

You'll have to use a rectangular area to store your elliptical image in as that is the only shape we can make bitmaps, pixmaps, pictures and images. The "trick", as Grimlock says, is to leave the pixels outside of the transparent.



if (!loaded.load(":/old-computer.jpg", "JPEG"))
{
QMessageBox::information(0, "loaded", "image loading failed...");
}

saved = new QPixmap(loaded.size());

QPainterPath clipPath;
clipPath.addEllipse(loaded.rect());

QPainter painter(saved);
painter.setClipPath(clipPath);

painter.drawImage(saved->rect(), loaded.toImage());

ui->loaded->setPixmap(loaded);
ui->saved->setPixmap(*saved);


ui->loaded and ui->saved are QLabels. loaded and saved are both QPixmaps, although saved is a pointer to a QPixmap.

Matthew.