PDA

View Full Version : How to create QPixmap from unsigned character array?



rashidbutt
16th May 2006, 08:02
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

rashidbutt
16th May 2006, 12:43
:confused:

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

Lele
16th May 2006, 14:02
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.



bool DisplayPainter3::DrawYBuffer(unsigned char* pBuffer, int w, int h)
{
unsigned char *chArr = newImage.bits();
memcpy(chArr,pBuffer,w*h);
return true;
}


hope this help,
bye

rashidbutt
16th May 2006, 18:17
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

wysota
16th May 2006, 18:25
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.