Results 1 to 4 of 4

Thread: QImage - Get the RGB component of a certain pixel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QImage - Get the RGB component of a certain pixel

    Hi everyone,

    I'm stuck with an issue that looks quite stupid to me. Nonetheless I don't seem to be smart enough to solve it... :/

    What I'm trying to do is simply to read the RGB values of a pixel contained in a QImage. To do so I'm using the following instructions:

    Qt Code:
    1. X = rand() % originalImage.width();
    2. Y = rand() % originalImage.height();
    3.  
    4. QRgb tempColorRgb = originalImage.pixel(QPoint(X,Y));
    5. QColor tempColor(tempColorRgb);
    6.  
    7. printf("RGB components of the pixel selected: %d %d %d\n", tempColor.red(), tempColor.green(), tempColor.blue());
    To copy to clipboard, switch view to plain text mode 

    What I get is that all the values look the same, whatever pixel I select. For example:

    RGB components of the pixel selected: 0 0 0
    RGB components of the pixel selected: 241 241 241
    RGB components of the pixel selected: 27 27 27


    OriginalImage is a QImage declared and initialised elsewhere in the code. It actually contains a jpeg picture loaded from the disk. I'm confident there's nothing wrong with it, as it is visible (it's displayed on my GUI) and accessible from the code above (I tried to save it with an instruction in the portion of the code below and everything went fine).

    Am I doing something obviously and terribly wrong which I can't notice?
    Last edited by fabietto; 1st July 2011 at 15:46. Reason: Simplified the code

Similar Threads

  1. QImage.pixel and Format_Indexed8
    By chef_seppel in forum Newbie
    Replies: 2
    Last Post: 29th September 2010, 22:17
  2. Shifting a QImage up by 1 pixel row
    By MSUdom5 in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2010, 10:25
  3. QImage direct pixel access.
    By hickscorp in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2010, 10:23
  4. QImage Pixel Coordinations
    By strateng in forum Newbie
    Replies: 2
    Last Post: 6th May 2010, 10:00
  5. Multithreaded per pixel operations on QImage
    By N¤X in forum Qt Programming
    Replies: 8
    Last Post: 14th September 2009, 12:29

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.