WebSockets - 将图像发送到连接的客户端 [英] WebSockets-Sending image to Clients connected

查看:105
本文介绍了WebSockets - 将图像发送到连接的客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在stackoverflow.com上的第一篇文章,所以我会尽量直截了当。
我必须使用websockets开发webapp的功能。我能够使用websockets发送文本数据
,但不是图像。我已经看了并尝试了不同的可能性,但是无法做到图片的处理必须是javascript。

This is my first post on stackoverflow.com so I will try to be straightforward. I have to develop a functionality of an webapp using websockets.I am able to send text data using websockets,but not an image.I've looked and tryied different possibilies,but couldn't make it work.The processing of the image has to be in javascript.

如果您有解决方案,请帮助我。
谢谢。

Please help me if you have a solution. Thanks.

更新:我已成功使用HTML5的FileReader Api发送带有websockets的图像。
感谢大家。

Update : I've succeded to send an image with websockets using the FileReader Api of HTML5. Thanks to everyone.

推荐答案

Websockects无法发送图像或二进制数据以外的任何内容。您可以通过将图像运行时转换为Base64数据并通过javascript将其解码为图像来解决此问题。

Websockects can't send images or anything else than binary data. You can solve this by converting the image runtime to Base64 data and decoding it through javascript to an image.

有很多关于如何解码Base64编码图像的示例,但你也可以直接将它嵌入图像src:< img src =data:image / png; base64,xxxxxxxxxxxxxxxxxx/> 你在哪里替换x使用您的Base64数据。

There are a lot of examples of how to decode a Base64 encoded image, but you can also embed it in the image src directly: <img src="data:image/png;base64,xxxxxxxxxxxxxxxxxx" /> where you replace the x'es with your Base64 data.

这篇关于WebSockets - 将图像发送到连接的客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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