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 do I convert QImage in Format_ARGB32 data to a pointer unsigned int*?

How do I convert QImage in Format_ARGB32 data to a pointer unsigned int*?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 3.3k 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.
  • P Offline
    P Offline
    prerna1
    wrote on last edited by
    #1

    I want to convert a QImage of format RGB888 to ARGB32 & fetch pixel data as unsigned int*.

    I can do the following to convert to ARGB32

    @QImage new = old.convertToFormat(QImage::Format_ARGB32);@

    However, are the pixels stored signed or unsigned?

    I need a pointer unsigned int* data, such that,

    an unsigned int (32 bits) holds a pixel in ARGB format, which from left to right is as follows:

    • the first 8 bits are for the alpha channel (and are ignored)
    • the next 8 bits are for the red channel
    • the next 8 bits are for the green channel
    • the last 8 bits are for the blue channel
      How do I do this?
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      @quint32 argbPtr = reinterpret_cast<quint32>(newImage.bits())@

      And you should be good to go.

      EDIT: corrected cast type, sorry for the error

      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
      • P Offline
        P Offline
        prerna1
        wrote on last edited by
        #3

        Then I will need to convert from quint32* to uint* or unsigned int*. How will I do that?
        [quote author="SGaist" date="1381869224"]Hi,

        @quint32 argbPtr = static_cast<quint32>(newImage.bits())@

        And you should be good to go.[/quote]

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vaquita Tim
          wrote on last edited by
          #4

          You should avoid using an int in this case, since you want it to be explicitly 32 bits. quint32 is exactly what you want and will be platform/compiler independent.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            prerna1
            wrote on last edited by
            #5

            Umm.... 1st of all, doing
            quint32 argbPtr = static_cast<quint32>(newImage.bits())
            gives me an error.

            Secondly, I need to get uint*, since I have to pass it through another function belonging to some other library.

            [quote author="Timothy" date="1382019170"]You should avoid using an int in this case, since you want it to be explicitly 32 bits. quint32 is exactly what you want and will be platform/compiler independent.[/quote]

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Vaquita Tim
              wrote on last edited by
              #6

              bq. quint32 argbPtr = static_cast<quint32>(newImage.bits())
              you forgot the *'s :-)

              1 Reply Last reply
              0
              • P Offline
                P Offline
                prerna1
                wrote on last edited by
                #7

                I still get an error:
                error: invalid static_cast from type 'uchar*' to type 'quint32*'
                [quote author="Timothy" date="1382020222"]bq. quint32 argbPtr = static_cast<quint32>(newImage.bits())
                you forgot the *'s :-)
                [/quote]

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  NicuPopescu
                  wrote on last edited by
                  #8

                  @uint bits = reinterpret_cast<uint>(image.bits());@

                  or

                  @uint bits = (uint)image.bits();@

                  and check the sizeof(uint) to be sure is 4

                  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