简体   繁体   English

如何在C ++中通过wxSocket发送wxImage?

[英]How can I send an wxImage through wxSocket in c++?

How can I send a wxImage through TCP wxSocket in c++? 如何在C ++中通过TCP wxSocket发送wxImage?
Should I convert the wxImage to a wxString or can it be directly send over? 我应该将wxImage转换为wxString还是可以直接发送过来? In that case how do I convert a wxImage tobe a wxString? 在那种情况下,如何将wxImage转换为wxString?

You have direct access to the image data via its GetData() member, so you could just send it directly, at least if you have an image without alpha. 您可以通过其GetData()成员直接访问图像数据,因此至少可以直接发送它,至少如果您有不带alpha的图像。 However in practice, compressing it first would probably be a good idea as uncompressed images are huge. 但是实际上,由于未压缩的图像非常大,因此首先压缩它可能是一个好主意。 You could either use zlib compression or, perhaps simpler, write the image in PNG or JPEG format to a memory buffer and send this buffer instead. 您可以使用zlib压缩 ,或者可能更简单,将PNG或JPEG格式的图像写入内存缓冲区,然后发送该缓冲区。

Converting the image to a string would be possible too but highly suboptimal. 将图像转换为字符串也是可能的,但是次优。

Hai wxImage :: GetData()返回unsigned char *,因此您可以轻松地以字符串形式发送图像。不要忘记发送图像的宽度和高度,这两个属性必须再次用于将数据转换为图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM