Changing color/transparency of certain image pixels



  • My program calculates certain points through a mathematical function and then create symmetrical pattern with the data of those particular image points. When I want to display the user which pixels are being selected the program is unable to change the color/transparency of that image on the original image itself. Here is the code:

    void Interface::updateImageDataGraph()
    {
        QRgb value;
        QImage original(imageSetPath + "/" + openImageName);
        original.load(imageSetPath + "/" + openImageName);
        original = QImage(original.width(), original.height() , QImage::Format_ARGB32);
        for(int i=0; i<original.height(); i++){
            QRgb *line = (QRgb *)original.scanLine(i);
            for(int j=0; j<original.width(); j++){
                QRgb pixelData = line[j];
                unsigned int red = qRed(pixelData);
                unsigned int green = qGreen(pixelData);
                unsigned int blue = qBlue(pixelData);
                value = qRgba(red, green, blue, 127);
                original.setPixel(j,i, value);
            }
        }
        float numberOfPixels = selectedPixelX.size();
        qDebug()<<"number of pixels:"<<numberOfPixels<<"\n";
        for(float i= 0; i< numberOfPixels; i++){
            QRgb pixelData = original.pixel(selectedPixelX[i], selectedPixelY[i]);
            unsigned int red = qRed(pixelData);
            unsigned int green = qGreen(pixelData);
            unsigned int blue = qBlue(pixelData);
            //qDebug()<<"red:"<<red<<"blue:"<<blue<<"green:"<<green<<"\n";
            value = qRgba(red+50, green+50, blue+50, 256);
            original.setPixel(selectedPixelX[i],selectedPixelY[i], value);
        }
    
        imagePixmap.convertFromImage(original);
        imagePixmap = imagePixmap.scaledToHeight(previewSize);
        imageLabel->setPixmap(imagePixmap);
        prevDataSeries->replace(imageDataSeries->pointsVector());
    }
    

    Thanks for helping.


  • Lifetime Qt Champion

    Hi,

    Can you show what you get and what you expect to get ?



  • @SGaist hey I am unable to upload images to the forum, I get an error saying something went wrong while parsing server response. Is there any other way I could share the image with you?



  • @SGaist
    alt text

    Okay so got the image uploaded. My intention is to plot that scatterplot on the image itself. So I was thinking that I got the scatterplots points then select those points on the image and convert the pixel color of those particular pixel as it would be easier for the user to figure out which part of the pictures are being selected. But I am unable to see any changes on the images.

    Could you guide to as to what is wrong in my code or is there a more efficient way to get it done.

    Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.