如何通过套接字将图像从Android发送到Qt服务器? [英] How to send an image from Android to a Qt server over a socket?

查看:103
本文介绍了如何通过套接字将图像从Android发送到Qt服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C ++编写的android和server服务器,用Qt编写,用TCP / IP套接字连接。连接正常。



我需要的是客户端将一个字节数组(图像位图)发送到服务器和服务器以检索图像并显示它。我没有如何检索字节数组,将其转换为图像并在Qt中显示。



这是我的代码到目前为止。



Android客户端将图像发送为bytearray。这个代码工作正常,用android服务器测试。





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.


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.

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

    qDebug()<<Data;
}





有人可以请教我如何从java客户端检索字节数组并将其显示为图像在基于Qt的服务器?或者如何解码bytearray?



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?

推荐答案

这篇关于如何通过套接字将图像从Android发送到Qt服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆