Important: Please read the Qt Code of Conduct -

Displaying an image on Rgb channel

  • Hi everybody ^^ I've been working on a project lately,dealing with image compression.for a primar task,i have to develop an application that shows and image,then display it on the red,green and blue channels.for now I managed to display the image itself seccessfuly,but i couldn't extract it on any of the Rgb's a piece of my code where i'm working on the red channel:

    QImage im;
    im.load(//path of my image);
    QVector <QRgb> table=im.colorTable();
    for(int i=0;table.size();i++) {
    QPixmap redvue;
    redvue= QPixmap::fromImage(im);
    QGraphicsScene *scene=new QGraphicsScene(m_ui->GraphicsScene);

    [EDIT: code formatting, please wrap in @-tags, Volker]

  • The problem is that you have probably an image in true color without color palette.

    To get the color, in such a case:

    QImage im(//the path);

    QVector c[im.width()][im.height];

    for (int i = 0; i<im.width(); i++)
    for (int j=0; j<im.height(); j++)
    c[i][j] = qRed(im.pixel());


Log in to reply