【发布时间】:2020-05-04 22:30:39
【问题描述】:
我正在使用此代码块从 python 发送图像以显示在 HTML 中。
x = cv2.imread(file)
x = cv2.cvtColor(x, cv2.COLOR_RGB2BGR)
img = io.BytesIO()
x = Image.fromarray(x, 'RGB')
x.save(img, 'PNG')
img.seek(0)
array.append(base64.b64encode(img.getvalue()))
k= k+1
id.append(k)
render_template('html_page.html', data=zip(array,id))
在 HTML 页面中显示的代码:
{%for i,j in data%}
<img for="id{{i}}" style = "float:left; width: 180px;" src="data:image/PNG;base64,{{ i }}" alt="display_Image">
{% endfor %}
图片没有显示在浏览器中。
谁能指出我做错了什么?尝试用 Python 学习图像处理。
在调试时,我可以看到图像在 python 函数中成功加载,但没有显示在 HTML 页面中。
【问题讨论】: