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
Forum Updated to NodeBB v4.3 + New Features

Convert Qbytearray to QImage

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 7 Posters 2.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.
  • 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