Results 1 to 5 of 5

Thread: How to create QPixmap from unsigned character array?

  1. #1

    Question How to create QPixmap from unsigned character array?

    Hi all,

    I m developing a Client in QT-1.44 on Redhat 6.1 to access my server written in C# on Windows platform. Its an application like VNC where my server sends its client the updates of its screen in form of byte array and client updates its display window to represent the server desktop changes.

    My problem is that i m not an expert of Qt-1.44( required by my Org.) and doesnt know how to convert the byte array into an image form that can be displayed on the display window. Also byte array can be a comprssed image data like jpeg, png.

    My Server code in C# roughly is as:

    MemoryStream ms = null;
    System.Text.ASCIIEncoding encoding =
    new System.Drawing.Imaging.EncoderParameters eps = null;
    System.Drawing.Imaging.ImageCodecInfo ici = null;

    ms = new MemoryStream();
    eps = new System.Drawing.Imaging.EncoderParameters(1);
    eps.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Dra wing.Imaging.Encoder.Quality,
    (long)80);
    ici = GetEncoderInfo("image/png");
    desktopbitmap.Save(ms, ici, eps);

    ms.Flush();
    desktopbitmap.Dispose();
    byte[] buffer = ms.GetBuffer();
    long arrayLength = ms.Length;

    //first send client length of the buffer
    byte[] length = encoding.GetBytes(Convert.ToString(arrayLength));
    socketForClient.Send(length, 0, length.Length,
    System.Net.Sockets.SocketFlags.None);

    //now send the actual buffer data
    socketForClient.Send(buffer , 0, buffer.Length, System.Net.Sockets.SocketFlags.None);

    Now my client in QT have to get the length and byte array data and then have to display the image appropriatly.

    Thanx for ur +ve responses.

    Rahsid Mahmood

  2. #2

    Unhappy Re: How to create QPixmap from unsigned character array?



    I think there must be a way to convert unsigned character array into image or bitmap.

    so please help me.

    I m in great trouble.

    Thanx for ur considerations.

    Rashid Mahmood

  3. #3
    Join Date
    Jan 2006
    Posts
    122
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create QPixmap from unsigned character array?

    Well, I'm not into C# but I had the chance to load a raw buffer into a Qimage, this is how I did it.

    Qt Code:
    1. bool DisplayPainter3::DrawYBuffer(unsigned char* pBuffer, int w, int h)
    2. {
    3. unsigned char *chArr = newImage.bits();
    4. memcpy(chArr,pBuffer,w*h);
    5. return true;
    6. }
    To copy to clipboard, switch view to plain text mode 

    hope this help,
    bye

  4. #4

    Unhappy Re: How to create QPixmap from unsigned character array?

    Thanx for ur response.

    I have tried the code but its not working.

    I think the problem is with receiving end of the client socket.

    Actually i m doing development in QT-1.44 where no socket classes
    available so i used system socket of the Redhat Linux to receive the byte
    array.

    Any suggestion regarding to client side development using QT to display the remote
    machine desktop.

    Thanx again.

    Rashid Mahmood

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to create QPixmap from unsigned character array?

    Docs for Qt1 are not available on Trolltech site anymore, so it's hard to tell you a complete solution. You should look for a QPixmap constructor that takes an array of bytes, just as QPixmap::QPixmap( const char * const[] xpm ) does.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.