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. How to paint color on gray image !
Qt 6.11 is out! See what's new in the release blog

How to paint color on gray image !

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.4k Views 2 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.
  • DQUY05D Offline
    DQUY05D Offline
    DQUY05
    wrote on last edited by
    #1

    Hi,
    How to paint color on gray image ! I tried like this, but the end result is still Gray image
    Can someone help me?
    Thanks!

    QImage img= QImage((const unsigned char*)(videoFrame.data),
                                             videoFrame.cols,videoFrame.rows,
                                             QImage::Format_Grayscale8);    // format Gray
    
                         QPainter painter;
                         QBrush brush=QBrush(QColor(Qt::red));  //   I need paint color on gray image (img)
                         painter.begin(&img);
                         painter.fillRect(0,0,100,100,brush);
                         painter.end();
    
                         ui->label_2->setPixmap(QPixmap::fromImage(img));
    
    O 1 Reply Last reply
    0
    • DQUY05D DQUY05

      Hi,
      How to paint color on gray image ! I tried like this, but the end result is still Gray image
      Can someone help me?
      Thanks!

      QImage img= QImage((const unsigned char*)(videoFrame.data),
                                               videoFrame.cols,videoFrame.rows,
                                               QImage::Format_Grayscale8);    // format Gray
      
                           QPainter painter;
                           QBrush brush=QBrush(QColor(Qt::red));  //   I need paint color on gray image (img)
                           painter.begin(&img);
                           painter.fillRect(0,0,100,100,brush);
                           painter.end();
      
                           ui->label_2->setPixmap(QPixmap::fromImage(img));
      
      O Offline
      O Offline
      ollarch
      wrote on last edited by
      #2

      @DQUY05 convert the image to RGB.

      DQUY05D 1 Reply Last reply
      3
      • O ollarch

        @DQUY05 convert the image to RGB.

        DQUY05D Offline
        DQUY05D Offline
        DQUY05
        wrote on last edited by
        #3

        Dear Mr. @ollarch
        Is this what you mean? I tried it, and it's red, but the original gray (img) image is lost

        QImage img= QImage((const unsigned char*)(videoFrame.data),
                                                 videoFrame.cols,videoFrame.rows,
                                                 QImage::Format_Grayscale8);    // format Gray
        
                             QImage img2{img.size(), QImage::Format_RGB888};  //    convert to RGB
        
                             QPainter painter;
                             QBrush brush=QBrush(QColor(Qt::red));  //   I need paint color on gray image (img)
                             painter.begin(&img2);
                             painter.fillRect(0,0,100,100,brush);
                             painter.end();
        
                             ui->label_2->setPixmap(QPixmap::fromImage(img2));
        
        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          start with an RGB colorspace image and rectfill it with the RGB values that would make it grey, then overlay any other colors you want, where you want.

          The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

          1 Reply Last reply
          0
          • DQUY05D Offline
            DQUY05D Offline
            DQUY05
            wrote on last edited by
            #5

            Hi,
            I converted to RGB and it worked
            Thanks !

            6d7c8169-9642-49e4-99d5-3f076dd3c598-image.png

            1 Reply Last reply
            0
            • DQUY05D DQUY05 has marked this topic as solved on

            • Login

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