通过套接字从python向android发送图像

2024-03-28 14:27:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前有一个pythonsocket服务器,它使用opencv从网络摄像头捕获。我已经用image.to字符串()

我正在尝试将这个图像发送到android应用程序,并在web视图中打开它。我可以打开文本字符串,但无法将其还原为图像。在

这是在web视图中显示任何内容的唯一方法:

webv.loadData(html, "text/html", "utf-8");

数据正在传输到android设备上,所以我知道socket工作正常,我就是搞不懂翻译。在

有什么建议吗?在

根据以下评论进行编辑:

好吧。因此,在发送字符串之前,我在python中将字符串转换为base64。在

我尝试使用bitmapfactory将图像添加到ImageView中,方法是:

^{pr2}$

但我得到了错误 SkImageDecoder::工厂返回null

我还尝试了下面的webview,它给了我一个坏掉的图像图标

String html = "<img src=\"data:image/jpeg;base64,"+result+"\" />";
webv.loadData(html, "text/html", "utf-8");

这些给了我一个空白的网络视图

String html = "<img src=\"data:image/jpeg;base64,"+result+"\" />";
webv.loadData(html, "iamge/jpeg", "base64");

String html = "<img src=\"data:image/jpeg;base64,"+result+"\" />";
webv.loadData(html, "text/html", "base64");

webv.loadData(result, "image/jpeg","base64");

问题似乎出在我的python代码中,因为导出到文本文件的base64字符串无法转换为图像,因此它“包含错误” 适用代码片段:

img = cv.QueryFrame(cam)
imgstr = base64.b64encode(img.tostring())

conn = s.accept()
conn.send(imgstr)

Tags: 字符串text图像imagesrc视图imgdata