Important: Please read the Qt Code of Conduct -

Fetching RGB values of a pixel

  • I am trying to fetch RGB values of a pixel using the following method

    @QRgb nil=image.pixel(x,y);
    QColor fin(nil);
    int r,g,b;
    r =;
    g =;
    b =; @

    This is is giving out of range exception for the given pixel coordinates though they are valid. I am I doing it right ? Can some one tell the best way to fetch rgb values of a pixel if the above isn't.

  • Try this:
    @QRgb nil=image.pixel(x,y);
    int r,g,b;
    r = qRed (nil);
    g = qGreen (nil);
    b = qBlue ( nil);@

Log in to reply