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. Changing Pixmap Color transition (Saturation, hue..)
Forum Updated to NodeBB v4.3 + New Features

Changing Pixmap Color transition (Saturation, hue..)

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.9k 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.
  • F Offline
    F Offline
    Faruq
    wrote on last edited by
    #1

    Hi everyone ,

    I am exploring on how to change the pixmap color but to no avail. I tried looking around and came across an obsolete class QPixmapFilter. It is no longer in used so I am wondering what other source should I look out for. My intention is to change the color of existing picture (Say a picture of a blue laptop). I want to change its color to red. I would like to make sure it change its color from blue to red in a smooth transition.

    Thank you and look forward for reply and discussions.

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      QPixmap.toImage()

      ...define smooth transition. are you talking about animated changes or gradients? QPixmap is not meant to be edited. You copy it to a QImage and then you have access to the raw pixel data.

      I light my way forward with the fires of all the bridges I've burned behind me.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Faruq
        wrote on last edited by
        #3

        Hi Kent-Dorfman,

        Thanks for the reply. Smooth color transition. I believe it would be the gradients from red to blue. So that means I must use QImage? The reason why I use QPixmap is because I wanted to put it under QLabel.

        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          I think you misunderstand. you must copy the image to QImage to do the pixel manipulation, but then you can retype it back to any other compatible format you desire. You just cannot edit it in QPixmap format.

          I light my way forward with the fires of all the bridges I've burned behind me.

          1 Reply Last reply
          1
          • F Offline
            F Offline
            Faruq
            wrote on last edited by
            #5

            Hi Kent-Dorfman,

            I managed to change to QImage and do the pixel manipulation. I used loops to do the manipulation pixel by pixel. I felt that it is inefficient. Is there anyway it can be more efficient? Or using loops is the only way to achieve this?

            What was done was, Using Qt logo as the QImage, I managed to change its green to red. but it go from left to right, from up to down. (Using loops).

            J.HilkJ 1 Reply Last reply
            0
            • F Faruq

              Hi Kent-Dorfman,

              I managed to change to QImage and do the pixel manipulation. I used loops to do the manipulation pixel by pixel. I felt that it is inefficient. Is there anyway it can be more efficient? Or using loops is the only way to achieve this?

              What was done was, Using Qt logo as the QImage, I managed to change its green to red. but it go from left to right, from up to down. (Using loops).

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              hi @Faruq if you use something like setPixel then that is going to be extremely slow.

              you're recommended to use scanLine or bits to access the pixel data


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              F 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                hi @Faruq if you use something like setPixel then that is going to be extremely slow.

                you're recommended to use scanLine or bits to access the pixel data

                F Offline
                F Offline
                Faruq
                wrote on last edited by
                #7

                @J.Hilk

                Thank you for replying. Hmmm, i noted your suggestion but how do I exactly use them ? I look at the documentation but have no idea how to start using scanLine or bits.

                J.HilkJ 1 Reply Last reply
                0
                • F Faruq

                  @J.Hilk

                  Thank you for replying. Hmmm, i noted your suggestion but how do I exactly use them ? I look at the documentation but have no idea how to start using scanLine or bits.

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by J.Hilk
                  #8

                  @Faruq

                  here is an example:

                  int main(int argc, char *argv[])
                  {
                      QApplication a(argc, argv);
                  
                      QImage img(400,400,QImage::Format_RGB888);
                      quint32 white(0xFFFFFFFF);
                      quint32 black(0x00000000);
                  
                      for(uint i(0), h(img.height()); i < h; i++) {
                         uchar *index = img.scanLine(i);
                         for(uint j(0), bbl(img.bytesPerLine()); j < bbl; j+=3){
                             memcpy(index+j, (i % 2) ? &black : &white, 3);
                         }
                      }
                  
                      QLabel lbl;
                      lbl.setPixmap(QPixmap::fromImage(img));
                      lbl.show();
                  
                      return a.exec();
                  }
                  

                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  F 1 Reply Last reply
                  2
                  • J.HilkJ J.Hilk

                    @Faruq

                    here is an example:

                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc, argv);
                    
                        QImage img(400,400,QImage::Format_RGB888);
                        quint32 white(0xFFFFFFFF);
                        quint32 black(0x00000000);
                    
                        for(uint i(0), h(img.height()); i < h; i++) {
                           uchar *index = img.scanLine(i);
                           for(uint j(0), bbl(img.bytesPerLine()); j < bbl; j+=3){
                               memcpy(index+j, (i % 2) ? &black : &white, 3);
                           }
                        }
                    
                        QLabel lbl;
                        lbl.setPixmap(QPixmap::fromImage(img));
                        lbl.show();
                    
                        return a.exec();
                    }
                    
                    F Offline
                    F Offline
                    Faruq
                    wrote on last edited by
                    #9

                    @J.Hilk thank you J.Hilk. I will work/play into it and let you know by the end of this weekend.

                    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