Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a client in android and server in C++, written using Qt, connected with a TCP/IP socket. The connection works fine.

What I need is that client sends a byte array (image bitmap) to server and server to retrieve the image and displays it. I have no how to retrieve the byte array, convert it as an image and show it in Qt.

This is my code so far.

The Android client sends image as bytearray. This code works ok, tested with android server.


Java
ImageView imageView=(ImageView) findViewById(R.id.imageView1);
Bitmap bmp=((BitmapDrawable)imageView.getDrawable()).getBitmap();

ByteArrayOutputStream bos = new ByteArrayOutputStream();
bmp.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] array = bos.toByteArray();

OutputStream out = socket.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.writeInt(array.length);
dos.write(array, 0, array.length);


This is how I get the data on the server.

C++
void MyThread::readyRead()
{
   QByteArray Data = socket->readAll();

    qDebug()<<Data;
}


Can somebody please give me a hand on how to retrieve the byte array from java client and display it as image in Qt-based server? or how to the decode the bytearray?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900