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. Convert Qbytearray to QImage

Convert Qbytearray to QImage

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 7 Posters 1.9k 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.
  • S Offline
    S Offline
    sharath
    wrote on last edited by sharath
    #1

    Hi All,

    How to convert Qbytearray data to Qimage, its in the below format

    "\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xFF\xDB\x00""C\x00\b\x06\x06\x07\x06\x05\b\x07\x07\x07\t\t\b\n\f\x14\r\f\x0B\x0B\f\x19\x12\x13\x0F\x14\x1D\x1A\x1F\x1E\x1D\x1A\x1C\x1C $.' \",#\x1C\x1C(7),01444\x1F'9=82<.342\xFF\xC0\x00\x0B\b\x02\b\x02\b\x01\x01\x11\x00\xFF\xC4\x00\x1F\x00\x00\x01\x05\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0B\xFF\xC4\x00\xB5\x10\x00\x02\x01\x03\x03\x02\x04\x03\x05\x05\x04\x04\x00\x00\x01}\x01\x02\x03\x00\x04\x11\x05\x12!1A\x06\x13Qa\x07\"q\x14""2\x81\x91\xA1\b#B\xB1\xC1\x15R\xD1\xF0$3br\x82\t\n\x16\x17\x18\x19\x1A%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz\x83\x84\x85\x86\x87\x88\x89\x8A\x92\x93\x94\x95\x96\x97\x98\x99\x9A\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFF\xDA\x00\b\x01\x01\x00\x00?\x00\xF0\n(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A(\xA2\x8A*\xF5\x9E\x8D\xAAj0\x99\xACt\xDB\xCB\x98\x83m/\x04\f\xEA\x0F\\d\x0E\xBC\x8F\xCE\xAC\x7F\xC2/\xE2\x0F\xFA\x01j\x7F\xF8\t'\xF8U\xDB?\x01x\xA6\xFA#$:4\xEA\xA1\xB6\xE2r\xB0\xB6~\x8E""A\xC7=zU\x9F\xF8V\x9E/
    

    then

      QImage image;
      qDebug()<<"img data::"<<image.loadFromData(socket->readAll(),"PNG");
    

    returning False here;

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gerd
      wrote on last edited by
      #2

      Hi,
      your data are not in png format...
      Try it without forcing an image format so the image load function can guess the format from the data

      S 1 Reply Last reply
      0
      • G Gerd

        Hi,
        your data are not in png format...
        Try it without forcing an image format so the image load function can guess the format from the data

        S Offline
        S Offline
        sharath
        wrote on last edited by sharath
        #3

        Hi @Gerd,
        Thanks for replying.

        then also returning false.

        qDebug()<<"img data::"<<image.loadFromData(socket->readAll());
        
        J.HilkJ 1 Reply Last reply
        0
        • S sharath

          Hi @Gerd,
          Thanks for replying.

          then also returning false.

          qDebug()<<"img data::"<<image.loadFromData(socket->readAll());
          
          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @sharath said in Convert Qbytearray to QImage:

          socket->readAll()

          The data is apparently coming from a Tcp/Udp socket,
          how do you know you have all the needed data ?


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          S 1 Reply Last reply
          3
          • J.HilkJ J.Hilk

            @sharath said in Convert Qbytearray to QImage:

            socket->readAll()

            The data is apparently coming from a Tcp/Udp socket,
            how do you know you have all the needed data ?

            S Offline
            S Offline
            sharath
            wrote on last edited by
            #5

            hi @J-Hilk ,

            Thanks for reply.

            So how can i convert Bytearray data to QImage that are coming from Tcp socket?

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

              @sharath said in Convert Qbytearray to QImage:

              So how can i convert Bytearray data to QImage that are coming from Tcp socket?

              You have to make sure that all data for the is read from the socket. So you have to add some kind of protocol on your socket which helps you to know this.

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

              S 1 Reply Last reply
              3
              • Christian EhrlicherC Christian Ehrlicher

                @sharath said in Convert Qbytearray to QImage:

                So how can i convert Bytearray data to QImage that are coming from Tcp socket?

                You have to make sure that all data for the is read from the socket. So you have to add some kind of protocol on your socket which helps you to know this.

                S Offline
                S Offline
                sharath
                wrote on last edited by
                #7

                hi @Christian-Ehrlicher,

                Thanks for your reply.

                Is there any example code?

                aha_1980A 1 Reply Last reply
                0
                • S sharath

                  hi @Christian-Ehrlicher,

                  Thanks for your reply.

                  Is there any example code?

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @sharath

                  Developing own protocols is not easy, it requires lot's of experience to reinvent what is already there, and mostly don't pay off.

                  So could you tell us what you really want to achive? We have dozens of file transfer protocols, HTTP being the most known one. So why not use one of the established protocols?

                  Regards

                  Qt has to stay free or it will die.

                  S 1 Reply Last reply
                  3
                  • aha_1980A aha_1980

                    @sharath

                    Developing own protocols is not easy, it requires lot's of experience to reinvent what is already there, and mostly don't pay off.

                    So could you tell us what you really want to achive? We have dozens of file transfer protocols, HTTP being the most known one. So why not use one of the established protocols?

                    Regards

                    S Offline
                    S Offline
                    sharath
                    wrote on last edited by
                    #9

                    @aha_1980 i need to achieve live camera streaming like producer and consumer concept. In my case embedded application is producer and my mobile application is consumer using TCP.
                    How can i pass each frames from embedded application through TCP socket and receive those frames and display that frames on my mobile application.
                    If you give me some Example links that would really appreciated.

                    Thanks,
                    Sharath

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

                      As we already said you need to define a protocol. But for video streaming there are already working protocols which you can use -> search in the internet for it.

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

                      S 1 Reply Last reply
                      5
                      • Christian EhrlicherC Christian Ehrlicher

                        As we already said you need to define a protocol. But for video streaming there are already working protocols which you can use -> search in the internet for it.

                        S Offline
                        S Offline
                        sharath
                        wrote on last edited by
                        #11

                        @Christian-Ehrlicher I got to know that GStreamer is best fit for this. but there is no examples how to use it in Qt?
                        How can i send my imagedata to gst_pipeline? please provide some sample, so that i can start with it quickly.

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

                          By following the documentation like written in your other thread.

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

                          S 1 Reply Last reply
                          2
                          • SGaistS SGaist

                            By following the documentation like written in your other thread.

                            S Offline
                            S Offline
                            sharath
                            wrote on last edited by sharath
                            #13

                            @SGaist I didn't understand how to use that.
                            For each Frame should i repeat this step?

                            QImage img("images/qt-logo.png"); //in my case its frames 
                            img = img.convertToFormat(QImage::Format_ARGB32);
                            QByteArray ba(reinterpret_cast<const char *>(img.bits()), img.sizeInBytes());
                            QBuffer buffer(&ba);
                            buffer.open(QIODevice::ReadOnly);
                            player = new QMediaPlayer;
                            player->setMedia(QUrl("gst-pipeline: appsrc blocksize=4294967295 ! \
                                video/x-raw,format=BGRx,framerate=30/1,width=200,height=147 ! \
                                coloreffects preset=heat ! videoconvert ! video/x-raw,format=I420 ! jpegenc ! rtpjpegpay ! \
                                udpsink host=127.0.0.1 port=5000"), &buffer);
                            player->play();
                            
                            1 Reply Last reply
                            0
                            • JustSoleSoleJ Offline
                              JustSoleSoleJ Offline
                              JustSoleSole
                              wrote on last edited by
                              #14

                              Hi All,
                              I need to transmit some black and white photos from my client to server,
                              used QTcpServer and QTcpSocket.
                              At the client i transfer the BMP data into QImage ,then QByteArray obj,and at the server i turn it back into QImage.
                              I`m sure server has recive complete QByteArray,
                              because i still have some color BMP photos that can be correctly turned into QImage and show on my server UI.
                              So my question is why the Blacke&White ones strongly distort,but the color ones unaffected?

                                      ///Client transfer code
                                      //QImage save to QByteArray
                              	QByteArray qbtImageArray;
                              	QBuffer qBuffer(&qbtImageArray);
                              	qImg->save(&qBuffer, "bmp");
                              
                              	//Data length and index(for identify)
                              	NetImageDataHead objNet;
                              	objNet.nImageSize = qbtImageArray.size();
                              	objNet.nImageIndex = pNetDeviceParams->nIndex;
                              
                                      //Append head and data
                              	QByteArray qbtMsgArray;
                              	qbtMsgArray.append((char *)&objNet, sizeof(NetImageDataHead));
                              	qbtMsgArray.append(qbtImageArray);
                              
                                      //Server code
                                      //QByteArray to QImage
                                      QBuffer buffer(&qbImgData);
                                      QImageReader reader(&buffer, "bmp");
                                      QImage img = reader.read();
                                      pLabel->setPixmap(QPixmap::fromImage(img));
                              1 Reply Last reply
                              0
                              • Christian EhrlicherC Offline
                                Christian EhrlicherC Offline
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                Why do you hijack an old thread instead creating a new one with your specific problem.
                                Also please provide some code on hwo you send and receive your data in the new thread.

                                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
                                0

                                • Login

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