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. QSvgRenderer rendering on QImage leads to transparent color bleeding into result image
Qt 6.11 is out! See what's new in the release blog

QSvgRenderer rendering on QImage leads to transparent color bleeding into result image

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 5 Posters 1.7k 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.
  • H hexaden

    @Christian-Ehrlicher so, you mean that such conversion is invalid?

    QImage img(w, h, format);
    *fill image*
    auto bits = new uchar[img.sizeInBytes()];
    memcpy(bits, img.bits(), img.sizeInBytes());
    QImage restored(bits, w, h, format);
    
    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #9

    @hexaden I don't see any conversion in this code. The image data is simply copied into a buffer (bits) and later restored from there.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    H 1 Reply Last reply
    0
    • jsulmJ jsulm

      @hexaden I don't see any conversion in this code. The image data is simply copied into a buffer (bits) and later restored from there.

      H Offline
      H Offline
      hexaden
      wrote on last edited by
      #10

      @jsulm There is a lot of code between things, but that what I meant: uchar buffer is made from a first QImage, and then much later second QImage is made from that buffer, and I asked if that might cause problems.

      jsulmJ 1 Reply Last reply
      0
      • H hexaden

        @jsulm There is a lot of code between things, but that what I meant: uchar buffer is made from a first QImage, and then much later second QImage is made from that buffer, and I asked if that might cause problems.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #11

        @hexaden said in QSvgRenderer rendering on QImage leads to transparent color bleeding into result image:

        and I asked if that might cause problems

        No, unless the buffered data is changed before second image is created from this buffer. You also have to be careful: "The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer.", see https://doc.qt.io/qt-6/qimage.html#QImage-3

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hexaden
          wrote on last edited by hexaden
          #12

          @jsulm restored QImage is very local, and buffer lives in outer scope for much longer time. I will double check if that buffer is ever modified, but I'm pretty sure it is not ever touched for writing (there is no public interface for it to be changed).

          JoeCFDJ 1 Reply Last reply
          0
          • H hexaden

            @jsulm restored QImage is very local, and buffer lives in outer scope for much longer time. I will double check if that buffer is ever modified, but I'm pretty sure it is not ever touched for writing (there is no public interface for it to be changed).

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

            @hexaden can you post your svg here for me to try it out?

            H 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @hexaden can you post your svg here for me to try it out?

              H Offline
              H Offline
              hexaden
              wrote on last edited by
              #14

              @JoeCFD it's of different color but it doesn't matter.

              <?xml version="1.0" encoding="utf-8"?>
              <!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
              <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
              	 viewBox="0 0 51 51" enable-background="new 0 0 51 51" xml:space="preserve">
              <path id="SymbolPreviewStroke" fill="#24D900" transform="rotate(0,26,26)" d="M25.5,13.6L19,32h13L25.5,13.6z M25.5,18.1l4.4,12.4h-8.8L25.5,18.1z"/>
              </svg>
              
              1 Reply Last reply
              0
              • JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by JoeCFD
                #15

                It is a green triangle. I replaced one of my icons with yours and can not see any border.
                Ubuntu 22.04 and Qt 5.15.3

                    QFile file(filename);
                    file.open( QIODevice::ReadOnly );
                    QString str( QString::fromUtf8( file.readAll() ) );
                
                    QSvgRenderer svgRenderer( str.toUtf8() );
                
                    QPixmap * pixmap = new QPixmap( QSize( image_width, image_height ) );
                    pixmap->fill( Qt::transparent );
                
                    QPainter pixPainter( pixmap );
                    svgRenderer.render(&pixPainter);
                
                H 1 Reply Last reply
                0
                • JoeCFDJ JoeCFD

                  It is a green triangle. I replaced one of my icons with yours and can not see any border.
                  Ubuntu 22.04 and Qt 5.15.3

                      QFile file(filename);
                      file.open( QIODevice::ReadOnly );
                      QString str( QString::fromUtf8( file.readAll() ) );
                  
                      QSvgRenderer svgRenderer( str.toUtf8() );
                  
                      QPixmap * pixmap = new QPixmap( QSize( image_width, image_height ) );
                      pixmap->fill( Qt::transparent );
                  
                      QPainter pixPainter( pixmap );
                      svgRenderer.render(&pixPainter);
                  
                  H Offline
                  H Offline
                  hexaden
                  wrote on last edited by
                  #16

                  @JoeCFD are you drawing a QPixmap or QImage on the actual screen?

                  JoeCFDJ 1 Reply Last reply
                  0
                  • H hexaden

                    @JoeCFD are you drawing a QPixmap or QImage on the actual screen?

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

                    @hexaden QPixmap

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      hexaden
                      wrote on last edited by
                      #18

                      So, I just tested things, turns out the problem is indeed in QImage reconstruction (at least I think so). QPixmap/QImage is painted just fine, without any issues, before deconstruction into array, and it is painted with color bleeding after reconstruction (in non-isolated example, with all program code inbetween).

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        hexaden
                        wrote on last edited by hexaden
                        #19

                        In the end, the mistake was very simple, in final image reconstruction Format_ARGB32 was used instead of Format_ARGB32_Premultiplied, causing these problems with drawing. Thanks everyone for help!

                        1 Reply Last reply
                        1
                        • H hexaden 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