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. pixmap to bytearray, bytearray to pixmap
Qt 6.11 is out! See what's new in the release blog

pixmap to bytearray, bytearray to pixmap

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 918 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by IknowQT
    #1

    Use the grab() function of the chart viewer to get it as a pixmap. And save it as a bytearray in xml.
    When I load the file and put it in qlabel, the message QPixmap::scaled: Pixmap is a null pixmap occurs.

    QByteArray bArray;
    			QBuffer buffer(&bArray);
    			buffer.open(QIODevice::WriteOnly);
    			this->m_pChartViewer->grab().save(&buffer, "PNG");
    
    
    QPixmap fromBase64;
    		fromBase64.loadFromData(src.pixByte);
    this->ui.label->setPixmap(
    			fromBase64.scaled(
    				nw,
    				nh,
    				Qt::KeepAspectRatio, Qt::SmoothTransformation)
    		);
    

    Is there any way to solve it?

    The loadFromData function is returning false.
    I think this is the problem...

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      How do you save and read it in to/from the xml?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      I 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        How do you save and read it in to/from the xml?

        I Offline
        I Offline
        IknowQT
        wrote on last edited by IknowQT
        #3

        @Christian-Ehrlicher

        QS_FIELD(QByteArray, pixByte)									//	pixByte
        
        QByteArray bArray;
        			QBuffer buffer(&bArray);
        			buffer.open(QIODevice::WriteOnly);
        			this->m_pChartViewer->grab().save(&buffer, "PNG");
        
        			m_pStcInfo->pixByte = bArray;
        

        It has a bytearray as a member variable of the class.
        Assign here and save the value of the member variable of this class in xml format.

        ===============================================================================

        5c25da8b-094f-4d91-b718-d8e802edeb5d-image.png
        <pixByte>�PNG </pixByte>

        I have captured the contents stored in the xml file.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can/must not simply but a QByteArray in a xml - you have to encode it e.g. as base64 and decode it later on.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          I 1 Reply Last reply
          3
          • Christian EhrlicherC Christian Ehrlicher

            You can/must not simply but a QByteArray in a xml - you have to encode it e.g. as base64 and decode it later on.

            I Offline
            I Offline
            IknowQT
            wrote on last edited by
            #5

            @Christian-Ehrlicher

            Thank you for answer. Thanks it has been resolved.
            When I save it as tobase64, the size of the file has definitely increased.
            I think it was probably because of a lot of text. Is there any way to reduce the file size?

            The method I tested was to save it as a QString, then convert it to tobase64() and convert it back to frombase64.

            But I didn't see the results I wanted.
            Is there any way to reduce the file size?

            Christian EhrlicherC 1 Reply Last reply
            0
            • I IknowQT

              @Christian-Ehrlicher

              Thank you for answer. Thanks it has been resolved.
              When I save it as tobase64, the size of the file has definitely increased.
              I think it was probably because of a lot of text. Is there any way to reduce the file size?

              The method I tested was to save it as a QString, then convert it to tobase64() and convert it back to frombase64.

              But I didn't see the results I wanted.
              Is there any way to reduce the file size?

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @IknowQT said in pixmap to bytearray, bytearray to pixmap:

              When I save it as tobase64, the size of the file has definitely increased.

              I would be surprised if not - now only 64 instead 256 characters are used (only the really printable ones) - see https://en.wikipedia.org/wiki/Base64

              Is there any way to reduce the file size?

              Reduce the size of the picture, don't store pictures in xml.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              3

              • Login

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