Results 1 to 20 of 21

Thread: QImage Rotation and Translation & Invert Specific Colors

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QImage Rotation and Translation & Invert Specific Colors

    reference from THIS

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char** argv)
    4. {
    5. QApplication app(argc, argv);
    6. QPixmap pixmap("logo.png");
    7. QImage image = pixmap.toImage();
    8. QRgb col;
    9. int gray;
    10. int width = pixmap.width();
    11. int height = pixmap.height();
    12. for (int i = 0; i < width; ++i)
    13. {
    14. for (int j = 0; j < height; ++j)
    15. {
    16. col = image.pixel(i, j);
    17. gray = qGray(col);
    18. image.setPixel(i, j, qRgb(gray, gray, gray));
    19. }
    20. }
    21. pixmap = pixmap.fromImage(image);
    22. QLabel label;
    23. label.setPixmap(pixmap);
    24. label.show();
    25. return app.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 

    following example convert the image into an gray scale image.
    HERE:
    gray = qGray(col);
    convert the QRgb color set into a gray color.
    You can use QRed, QBlue etc. according to your need.
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

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

    2lights (14th August 2013)

Similar Threads

  1. Replies: 0
    Last Post: 23rd July 2013, 13:19
  2. Graph rotation
    By jomarin in forum Qwt
    Replies: 2
    Last Post: 16th August 2010, 09:21
  3. Ellipse and rotation
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 9th March 2009, 10:43
  4. Rotation on Qframe
    By Pharell in forum Qt Programming
    Replies: 11
    Last Post: 2nd April 2008, 16:31
  5. Replies: 3
    Last Post: 15th March 2006, 11:44

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.