Results 1 to 3 of 3

Thread: How to copy sellected ellipse area from image

  1. #1
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    1

    Default How to copy sellected ellipse area from image

    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.
    Attached Images Attached Images

  2. #2
    Join Date
    Nov 2008
    Location
    Częstochowa/Poland
    Posts
    50
    Thanks
    2
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to copy sellected ellipse area from image

    Cheat copy a rect and than set every thing outside the ellipse to alpha.
    Last edited by Grimlock; 24th September 2009 at 19:28.

  3. #3
    Join Date
    Jul 2008
    Location
    London, UK
    Posts
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to copy sellected ellipse area from image

    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.

    Qt Code:
    1. if (!loaded.load(":/old-computer.jpg", "JPEG"))
    2. {
    3. QMessageBox::information(0, "loaded", "image loading failed...");
    4. }
    5.  
    6. saved = new QPixmap(loaded.size());
    7.  
    8. QPainterPath clipPath;
    9. clipPath.addEllipse(loaded.rect());
    10.  
    11. QPainter painter(saved);
    12. painter.setClipPath(clipPath);
    13.  
    14. painter.drawImage(saved->rect(), loaded.toImage());
    15.  
    16. ui->loaded->setPixmap(loaded);
    17. ui->saved->setPixmap(*saved);
    To copy to clipboard, switch view to plain text mode 

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

    Matthew.

Similar Threads

  1. Selection area on image
    By sdwdd in forum Newbie
    Replies: 2
    Last Post: 5th March 2009, 12:09
  2. Replies: 3
    Last Post: 11th March 2007, 14:04
  3. displaying png image for a given area..
    By sar_van81 in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2007, 14:56

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.