Qt Forum

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

    Qt Academy Launch in California!

    Unsolved Convert Qbytearray to QImage

    General and Desktop
    7
    15
    750
    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.
    • S
      sharath @J.Hilk last edited by

      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 Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        @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 has to stay free or it will die.

        S 1 Reply Last reply Reply Quote 3
        • S
          sharath @Christian Ehrlicher last edited by

          hi @Christian-Ehrlicher,

          Thanks for your reply.

          Is there any example code?

          aha_1980 1 Reply Last reply Reply Quote 0
          • aha_1980
            aha_1980 Lifetime Qt Champion @sharath last edited by

            @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 Reply Quote 3
            • S
              sharath @aha_1980 last edited by

              @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 Reply Quote 0
              • Christian Ehrlicher
                Christian Ehrlicher Lifetime Qt Champion last edited by

                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 has to stay free or it will die.

                S 1 Reply Last reply Reply Quote 5
                • S
                  sharath @Christian Ehrlicher last edited by

                  @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 Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    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 Reply Quote 2
                    • S
                      sharath @SGaist last edited by sharath

                      @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 Reply Quote 0
                      • JustSoleSole
                        JustSoleSole last edited by

                        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 Reply Quote 0
                        • Christian Ehrlicher
                          Christian Ehrlicher Lifetime Qt Champion last edited by

                          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 has to stay free or it will die.

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