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. 2 QPixmap to 1 QPixmap: Problem with invisible pixels
Forum Update on Monday, May 27th 2025

2 QPixmap to 1 QPixmap: Problem with invisible pixels

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.0k Views
  • 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
    Jerome96
    wrote on 29 Dec 2013, 11:03 last edited by
    #1

    Hey guys!

    I'm writing a function to put a QPixmap on an other QPixmap.
    This works fine with this function:

    @void AImage::addPixmap(int x, int y, QPixmap pixmap){
    QImage pix = pixmap.toImage();
    QImage image = tile_image->getPixmap().toImage();

    int w = pix.width();
    int h = pix.height();
    
    float dX = 0;
    float dY = 0;
    
    for(int i = 0; i < image.width(); i++){
        for(int j = 0; j < image.height(); j++){
            if(i >= x && i <= x + w && j >= y && j <= y+h){
                if(QColor(pix.pixel(dX,dY)).){              // I want to check here if the pixel is invisible.. but how?
                    image.setPixel(i,j,pix.pixel(dX,dY));
                }
                dY++;
            }
        }
        if(dY > 0){
            dX++;
        }
        dY = 0;
    }
    
    QPixmap outPut = QPixmap::fromImage(image);
    tile_image->setPixmap(outPut);
    

    }@

    But how can I detect invisible pixels? I have a png file with some invisible pixels and don't want to put them on the background QPixmap.

    I hope you can help me and sorry for my bad English :)

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Seba84
      wrote on 29 Dec 2013, 20:32 last edited by
      #2

      I am not an expert on Image convertion but I found this on doc: "Alpha-Blended Drawing":http://qt-project.org/doc/qt-5/qcolor.html#alpha-blended-drawing

      bq. QColor also support alpha-blended outlining and filling. The alpha channel of a color specifies the transparency effect, 0 represents a fully transparent color, while 255 represents a fully opaque color.

      So I think your if-statement should be some thing like:
      @if(QColor(pix.pixel(dX,dY)).alpha() < 255 )@

      Hope it helps! :)

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jerome96
        wrote on 30 Dec 2013, 19:44 last edited by
        #3

        Thank you for the help :) but I tried this before. It won't work because every pixel of the image has an alpha of 255.

        I hope we get this problem solved :)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Seba84
          wrote on 30 Dec 2013, 22:07 last edited by
          #4

          That means that the image is all opaque and there is no invisible or transparent pixels: for me invisible is equal to transparent with alpha = 0. Maybe this assumption is incorrect, and is the root-cause of your problem.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jerome96
            wrote on 30 Dec 2013, 22:59 last edited by
            #5

            Yeah but there is a transparent background

            http://s29.postimg.org/5w2ix3eib/shield.png(http://s29.postimg.org/5w2ix3eib/shield.png)

            I uploaded the image. You have to save it then you will see there is a transparent background.

            But thank you for your help :)

            1 Reply Last reply
            0
            • R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 2 Jan 2014, 08:03 last edited by
              #6

              do you depend on this code? I mean there is a way easier method using QPainter:
              @
              void AImage::addPixmap(int x, int y, const QPixmap & pixmap)
              {
              QPixmap sourcePix = tile_image->getPixmap();

                  QPainter p(sourcePix);
                       p.drawPixmap( x, y, pixmap );
                  p.end();
              
                  tile_image->setPixmap(sourcePix);
              

              }
              @

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0

              2/6

              29 Dec 2013, 20:32

              topic:navigator.unread, 4
              • Login

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