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. image transfering[SOLVED]

image transfering[SOLVED]

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 1.8k Views 3 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.
  • M Offline
    M Offline
    mixcider
    wrote on last edited by mixcider
    #1

    hello,I'm studying about image transfering on Qt now.
    but it is difficult to finish making program.so please help me.
    now I'm thinking the way below:
    [server side]
    1.first get image data of web cam by OpenCV's function. cvCaptureFromCam()
    2.change the image data to QByteArray by QByteArray(img->imageData, img->imageSize)
    3.add image's length and height data to QByteArray by append()
    4.transfer the QByteArray Data by writeDatagram()
    [client side]
    1.get data by readDatagram()
    2.search length data and heidht data by QByteArray's function indexOf()
    3.change it to char pointer(char *) by
    char *cdata;
    cdata = store.data(); (store is QByteArray Data = image)
    4.change it to QImage by function(1)
    5.change it to QPixmap
    6.add it to Qlabel

    please,tell me how to do.

    function(1):
    QImage* MainWindow::char2QImage(char *cdata)
    {
    int channels = 3;
    QImage *qimg = new QImage(width_data, height_data, QImage::Format_ARGB32);
    char *data = cdata;

    for (int y = 0; y < height_data; y++, data += width_data * channels)
    {
        for (int x = 0; x < width_data; x++)
        {
            char r, g, b, a = 0;
            if (channels == 1)
            {
                r = data[x * channels];
                g = data[x * channels];
                b = data[x * channels];
            }
            else if (channels == 3 || channels == 4)
            {
                b = data[x * channels];
                g = data[x * channels + 1];
                r = data[x * channels + 2];
            }
         if (channels == 4)
            {
                a = data[x * channels + 3];
                qimg->setPixel(x, y, qRgba(r, g, b, a));
            }
            else
            {
                qimg->setPixel(x, y, qRgb(r, g, b));
            }
        }
    }
    return qimg;
    

    }

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

      Hi,

      Why not directly send a QImage ? That would avoid having to play with raw data of unknown size

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

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why not directly send a QImage ? That would avoid having to play with raw data of unknown size

        M Offline
        M Offline
        mixcider
        wrote on last edited by
        #3

        @SGaist
        Thank you for advising.

        I don't know the way to transfer the QImage data from server to client.
        so, I use this method.
        is it possible to transfer the QImage on UDPsocket communication?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Hi,

          You can use QDataStream to write/read a QImage on a QByteArray

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mixcider
            wrote on last edited by
            #5

            Thank you for telling me.

            I will try to use the QDataStream.

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

              To add to @mcosta, if you don't want to risk packet loss, then you should use TCP so QTcpSocket/Server

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

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mixcider
                wrote on last edited by
                #7

                Thank you for advising.
                I will try it.

                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