Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Raw pixel data to QPixmap without copying data

    General and Desktop
    3
    7
    8879
    Loading More Posts
    • 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.
    • D
      david.luggen last edited by

      Hey there,

      Is there a way I can create a QPixmap directly out of raw pixel data without copying this data?

      @
      QImage myImage = new QImage( ucharDataArray, w, h, w3, QImage::Format_RGB888);
      QPixmap *myPixmap = new QPixmap();
      *myPixmap = myPixmap->fromImage(*myImage);
      @

      As I create the QImage out of the data, this works to pass the data and not copy it. But when I try to create a QPixmap out uf the QImage it starts to copy the data. As I'm working with images that are of huge sizes (>1GB) this is something I need to avoid.

      One way would be to write a known Image header like the one from "BMP" in front of the data array, so the QPixmap::loadFromData method would regocnize the data as valable image. But this seems to be quite a hack. Does anyone know a simpler way? Thx for help!

      1 Reply Last reply Reply Quote 0
      • S
        stevenceuppens last edited by

        Maybe, you can load your data direclty into a QPixmap?

        @bool QPixmap::loadFromData(...)@

        Steven CEUPPENS
        Developer / Architect
        Mobile: +32 479 65 93 10

        1 Reply Last reply Reply Quote 0
        • D
          david.luggen last edited by

          Yes I tried that, but therefore I need to have raw data in a defined image format. These are BMP, GIF, JPG, JPEG, PNG, PBM, PGM, PPM , XBM, XPM.
          If I don't have any header, but only raw pixel data, the method doesn't accept the data as valable image and thus doesn't load anything.

          1 Reply Last reply Reply Quote 0
          • S
            stevenceuppens last edited by

            The QPixmap class is an off-screen image representation that can be used as a paint device.

            The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.

            Both class are quite different in terms of implementation, and i don't think it's currently possible to copy without data-copy...

            Why do you need a QPixmap?

            Steven CEUPPENS
            Developer / Architect
            Mobile: +32 479 65 93 10

            1 Reply Last reply Reply Quote 0
            • D
              david.luggen last edited by

              That may be the reason, that the implementation of both classes are different. Although I wonder how a QPixmap is representet. Because I can't think of a more naked representation, than a plain array that contains every pixel with 3 rgb 8-bit values in a row and the width information so you know where to start a new row.

              I need a QPixmap because its way faster to show it on screen than a QImage. Tried it once with QImage and the performance differences with such huge images are enormous.

              1 Reply Last reply Reply Quote 0
              • A
                agocs last edited by

                If this is about Qt 5 then the difference between QImage and QPixmap is negligible on most platforms given that a QPixmap will usually be backed by a QImage under the hood.

                Qt 4 was different in this respect since QPixmap was more likely to be backed by a platform-specific native image type there. This is not the case in 5.

                1 Reply Last reply Reply Quote 0
                • D
                  david.luggen last edited by

                  So in terms of Qt5 this means that if I put a QImage into my QGraphicsScene, the performance should stay the same or that it should be no problem to pass a QImage to a QPixmap without copying data?

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post