Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating a transparent image.
Forum Updated to NodeBB v4.3 + New Features

Creating a transparent image.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 771 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jay_Ladhad
    wrote on last edited by jsulm
    #1

    I am working on a project that requires me to make an image semi-transparent so that I can then plot a graph on that image.

    Problem: I am unable to make the whole image semi-transparent. The image is displayed using QLabel->setPixmap. I open the image and save it as a QImage and try to manipulate its alpha channel and then convert it to Pixmap.

    Code:

    void Interface::updateImageDataGraph()
    {
        QRgb value;
        QImage original(imageSetPath + "/" + openImageName);
        original.load(imageSetPath + "/" + openImageName);
        original = QImage(previewSize, previewSize, 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);
                qDebug()<<"RGB at ("<<i<<","<<j<<") is "<<red<<green<<blue<<endl;
                value = qRgba(red, green, blue, 127);
                original.setPixel(i,j, value);
            }
        }
        //original.fill(Qt::transparent);
        imagePixmap.convertFromImage(original);
        //imagePixmap.fill(Qt::transparent);
        imagePixmap = imagePixmap.scaledToHeight(previewSize);
        /*QPainter painter(this);
        painter.begin(&imagePixmap);
    
        painter.setOpacity(0.5);
        painter.end();*/
        imageLabel->setPixmap(imagePixmap);
        
        prevDataSeries->replace(imageDataSeries->pointsVector());
    }
    
    D 1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      I would try creating a new QPixmap using fromImage, instead of reusing the original pixmap. Maybe you retain some kind of color information that affects the outcome.

      1 Reply Last reply
      0
      • J Jay_Ladhad

        I am working on a project that requires me to make an image semi-transparent so that I can then plot a graph on that image.

        Problem: I am unable to make the whole image semi-transparent. The image is displayed using QLabel->setPixmap. I open the image and save it as a QImage and try to manipulate its alpha channel and then convert it to Pixmap.

        Code:

        void Interface::updateImageDataGraph()
        {
            QRgb value;
            QImage original(imageSetPath + "/" + openImageName);
            original.load(imageSetPath + "/" + openImageName);
            original = QImage(previewSize, previewSize, 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);
                    qDebug()<<"RGB at ("<<i<<","<<j<<") is "<<red<<green<<blue<<endl;
                    value = qRgba(red, green, blue, 127);
                    original.setPixel(i,j, value);
                }
            }
            //original.fill(Qt::transparent);
            imagePixmap.convertFromImage(original);
            //imagePixmap.fill(Qt::transparent);
            imagePixmap = imagePixmap.scaledToHeight(previewSize);
            /*QPainter painter(this);
            painter.begin(&imagePixmap);
        
            painter.setOpacity(0.5);
            painter.end();*/
            imageLabel->setPixmap(imagePixmap);
            
            prevDataSeries->replace(imageDataSeries->pointsVector());
        }
        
        D Offline
        D Offline
        Devopia53
        wrote on last edited by Devopia53
        #3

        @Jay_Ladhad

        When using the setPixel () function in the current code, the x, y coordinate system is being used incorrectly. Change like this:

        original.setPixel(j, i, value);

        And it is simple to using the combination of subclassing QLabel / overloading initPainter() / QPainter::setOpacity() or QGraphicsOpacityEffect.

        J 1 Reply Last reply
        2
        • D Devopia53

          @Jay_Ladhad

          When using the setPixel () function in the current code, the x, y coordinate system is being used incorrectly. Change like this:

          original.setPixel(j, i, value);

          And it is simple to using the combination of subclassing QLabel / overloading initPainter() / QPainter::setOpacity() or QGraphicsOpacityEffect.

          J Offline
          J Offline
          Jay_Ladhad
          wrote on last edited by
          #4

          @Devopia53 Thank you so much. I am completely new to this environment and would love to improve the efficiency of my program using the predefined functions.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved