Results 1 to 13 of 13

Thread: How can I copy image from anohter image

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How can I copy image from anohter image

    Line 2 has an error and should be checking the height not width.

  2. The following user says thank you to ChrisW67 for this useful post:

    chong_kimkeang (27th September 2012)

  3. #2
    Join Date
    Sep 2012
    Posts
    66
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How can I copy image from anohter image

    Hello everyone, for doing with polygon, I can't because it always can't be close. So could you tell me how to cut the image by using mask?

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How can I copy image from anohter image

    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:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6.  
    7. QImage source("Lenna.png");
    8.  
    9. // An arbitrary region to cut out
    10. QPolygon region;
    11. region << QPoint(10, 10) << QPoint(100, 200) << QPoint(500, 50);
    12.  
    13. // Let's do it
    14. path.addPolygon(region);
    15.  
    16. QImage cutout(source.size(), QImage::Format_ARGB32_Premultiplied);
    17. cutout.fill(Qt::transparent);
    18. QPainter p(&cutout);
    19. p.setClipPath(path);
    20. p.drawImage(0, 0, source);
    21. p.end();
    22.  
    23. QLabel l;
    24. l.setPixmap(QPixmap::fromImage(cutout));
    25. l.show();
    26.  
    27. return a.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to ChrisW67 for this useful post:

    chong_kimkeang (1st October 2012)

  6. #4
    Join Date
    Sep 2012
    Posts
    66
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How can I copy image from anohter image

    Hello everyone, I am very happy because now I can cut that image. Greatly thank everyone particularly the Expert ChrisW67 who give me the sample code which help me create this success.

Similar Threads

  1. Qwebview Copy Text And Save Image
    By ShapeShiftme in forum Qt Programming
    Replies: 4
    Last Post: 11th August 2016, 06:30
  2. Replies: 3
    Last Post: 3rd August 2012, 10:35
  3. Replies: 1
    Last Post: 29th November 2009, 20:33
  4. How to copy sellected ellipse area from image
    By adamsakli in forum Newbie
    Replies: 2
    Last Post: 24th September 2009, 22:11
  5. How to copy selected ellipse area from image
    By adamsakli in forum Qt Programming
    Replies: 5
    Last Post: 24th September 2009, 19:54

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
  •  
Qt is a trademark of The Qt Company.