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. Draw with alpha atop of QImage from blob
Forum Updated to NodeBB v4.3 + New Features

Draw with alpha atop of QImage from blob

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 577 Views 3 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.
  • SeeLookS Offline
    SeeLookS Offline
    SeeLook
    wrote on last edited by SeeLook
    #1

    Halo everyone,

    I need to draw a few things atop of QImage created from unsigned char* array.
    But drawing doesn't respect alpha channel and anti-aliasing.

    void processFrame(unsigned char* frameData, int w, int h, int lineSize) {
        QImage frameImage(frameData, w, h, lineSize, QImage::Format_ARGB32);
        QPainter p(&frameImage);
        p.setRenderHint(QPainter::Antialiasing);
    
        QColor c(255, 255, 255, 150); // white and translucent
        p.setPen(c);
        p.setBrush(c);
    
        p.drawRoundedRect(rectX, rectY, rectW, rectH, rectW / 35.0, rectH / 35.0);
        p.end();
    }
    

    I get only white, opaque rectangle.
    And for the record - this function is called from C code through C++ wrapper - so there is no QGuitApplication - if it matters.
    Did I miss something?

    Pl45m4P 1 Reply Last reply
    0
    • SeeLookS SeeLook

      Halo everyone,

      I need to draw a few things atop of QImage created from unsigned char* array.
      But drawing doesn't respect alpha channel and anti-aliasing.

      void processFrame(unsigned char* frameData, int w, int h, int lineSize) {
          QImage frameImage(frameData, w, h, lineSize, QImage::Format_ARGB32);
          QPainter p(&frameImage);
          p.setRenderHint(QPainter::Antialiasing);
      
          QColor c(255, 255, 255, 150); // white and translucent
          p.setPen(c);
          p.setBrush(c);
      
          p.drawRoundedRect(rectX, rectY, rectW, rectH, rectW / 35.0, rectH / 35.0);
          p.end();
      }
      

      I get only white, opaque rectangle.
      And for the record - this function is called from C code through C++ wrapper - so there is no QGuitApplication - if it matters.
      Did I miss something?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @SeeLook said in Draw with alpha atop of QImage from blob:

      Did I miss something?

      Yes :)

      QImage::Format_ARGB32

      Have a look here....

      QColor c(255, 255, 255, 150); // white and translucent

      ... and then look back here again :)

      Are you sure the format is correct?

      See here:

      • https://forum.qt.io/topic/94166/qimage-argb-and-rgba-alpha-channel-is-never-first-in-raw-bits

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      2
      • SeeLookS Offline
        SeeLookS Offline
        SeeLook
        wrote on last edited by SeeLook
        #3

        @Pl45m4 thanks for the answer.
        I wish it would be so easy...
        First of all, whatever blob data format is, QColor is QColor and its constructor takes arguments in that exact order (R, G, B, A).
        And I can get blob data in that format (RGBA8888), I've tried already - the same result.

        d267a95c-44b1-4db7-8c92-262a8294dcfc-image.png

        When I tried with color (127, 127, 127, 127) - the same, no transparency at all.

        Also there is no anti-aliasing - drawing doesn't react with underlying pixels.
        And I tested this QImage instance - pixel colors are as they should be - it looks like QPianter has problem with that painting device.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchinand
          wrote on last edited by
          #4

          Have you tried different Composition Modes?

          1 Reply Last reply
          1
          • JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #5

            QPainter painter(this);
            painter.setRenderHint(QPainter::Antialiasing);
            painter.drawImage(rectX, rectY, rectW, rectH,frameImage );
            your color setting is for background.

            1 Reply Last reply
            0
            • SeeLookS Offline
              SeeLookS Offline
              SeeLook
              wrote on last edited by
              #6

              Have you tried different Composition Modes?

              Yes.
              And it works when it comes to cover source (rectangle) but not for blending with blob image pixels.

              1 Reply Last reply
              1
              • SeeLookS Offline
                SeeLookS Offline
                SeeLook
                wrote on last edited by SeeLook
                #7

                QPainter painter(this);

                Maybe here is the thing... There is no any this.
                this is used when QPainter is used in GUI app - it is QWidget then or QGraphicsSceneItem or so.

                Here is only a library which uses bare QImage which is QPiantDevice for QPainter.

                JoeCFDJ 1 Reply Last reply
                0
                • SeeLookS SeeLook

                  QPainter painter(this);

                  Maybe here is the thing... There is no any this.
                  this is used when QPainter is used in GUI app - it is QWidget then or QGraphicsSceneItem or so.

                  Here is only a library which uses bare QImage which is QPiantDevice for QPainter.

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by JoeCFD
                  #8

                  @SeeLook Yes, "this" is the canvas for painting. I do not know where you paint it.

                  1 Reply Last reply
                  0
                  • SeeLookS Offline
                    SeeLookS Offline
                    SeeLook
                    wrote on last edited by
                    #9

                    @JoeCFD - over pixels of QImage from blob/raw data.
                    And those raw pixels are changed - as example image shows but QPainter doesn't react with original ones - just overwrites them.

                    JoeCFDJ 1 Reply Last reply
                    0
                    • SeeLookS SeeLook

                      @JoeCFD - over pixels of QImage from blob/raw data.
                      And those raw pixels are changed - as example image shows but QPainter doesn't react with original ones - just overwrites them.

                      JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by JoeCFD
                      #10

                      @SeeLook
                      add this to see what happens?
                      painter.drawImage(rectX, rectY, rectW, rectH,frameImage );

                      It seems only background is painted.

                      1 Reply Last reply
                      0
                      • SeeLookS Offline
                        SeeLookS Offline
                        SeeLook
                        wrote on last edited by SeeLook
                        #11

                        @JoeCFD
                        In example image I attached before - background is pink and rectangle is as it is.
                        And I also tried to draw that entire image again into painter:

                        p.drawImage(0, 0, frameImage);
                        

                        then draw that rectangle atop of all - still the same difference - no alpha.

                        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