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. QImage::setPixelColor vs QImage::setPixel
Forum Updated to NodeBB v4.3 + New Features

QImage::setPixelColor vs QImage::setPixel

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 5.1k 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.
  • QT-static-prgmQ Offline
    QT-static-prgmQ Offline
    QT-static-prgm
    wrote on last edited by
    #1

    hi,

    till now i used setPixelColor to change some Colors in my image. But since i compiled my code on a different pc with an older version i looked a little further in the function description.
    http://doc.qt.io/qt-5/qimage.html#setPixelColor

    It was introduced in 5.6 and the interesting part is this:

    Warning: This function is expensive due to the call of the internal detach() function called within; if performance is a concern, we recommend the use of scanLine() or bits() to access pixel data directly.

    So i changed it to void QImage::setPixel on the pc, because this is compatible with the older version of Qt (i think 4.8 is installed).

    So now i wonder what is better? setPixel or setPixelColor. For me both works, but setPixelColor says it is bad for runtime.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Usually you would take the function that does the right thing fast.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • QT-static-prgmQ Offline
        QT-static-prgmQ Offline
        QT-static-prgm
        wrote on last edited by
        #3

        Both do the job. How can I know what is faster??
        I don't even see the different between the two functions

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          If you want to know the difference: benchmark.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • frederikF Offline
            frederikF Offline
            frederik
            wrote on last edited by
            #5

            The functions are mostly the same and exist as convenience, so use the one which is most convenient with the data you have. Note that since QImage is implicitly shared, both functions detach if the image is referenced more than once.
            Depending on your use case, you may avoid them altogether, but that is only in case this is performance critical code and you share the image before doing the pixel operations. I would only investigate more if you need major performance improvements.

            1 Reply Last reply
            2

            • Login

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