如何将数据 uri 方案显示到 C# WebBrowser 控制器中
如何在 C# 中显示使用 WebBrowser 控件编码的图像 base64?
我使用了以下代码:
<img src="data:image/gif;base64,/9j/4AAQSkZJRgABAgAAZABkAA7AAR
R894ADkFkb2JlAGTAAAAAAfbAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBw
...
uhWkvoJfQO2z/rf4VpL6CX0Dts/63+FaS+gl9A7bP+tthWkvoJfQODCde4qfcg
RiNWK3UyUeX9CXpHU43diOK915X5fG/reux5hUAUBftZ" />
但没有显示图像。一种解决方案是将图像保存在本地并使用绝对路径,但这是不可取的。
有什么想法吗?
How can I show an image base64 encoded using WebBrowser control in C#?
I used the following code:
<img src="data:image/gif;base64,/9j/4AAQSkZJRgABAgAAZABkAA7AAR
R894ADkFkb2JlAGTAAAAAAfbAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBw
...
uhWkvoJfQO2z/rf4VpL6CX0Dts/63+FaS+gl9A7bP+tthWkvoJfQODCde4qfcg
RiNWK3UyUeX9CXpHU43diOK915X5fG/reux5hUAUBftZ" />
but no image is displayed. One solution would be to save images locally and using absolute path, but this is not desirable.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试在一个项目中这样做,但 IE(
WebBrowser
控件最终将使用它)成为限制因素 - 它只能容纳 32Kb 大小的图像。我最终不得不创建一个 HTTP 处理程序 (.ashx),它根据数据库密钥返回图像。编辑:示例 - 请注意数据库处理例程是专有的,您必须放入自己的例程。处理程序的其余部分将展示如何重新缩放图像(如果需要)并作为响应发送回浏览器:
I tried doing this for a project and IE (which the
WebBrowser
control will eventually use) became the limiting factor - it can only hold 32Kb-sized images. I wound up having to create an HTTP handler (.ashx) that returned the image based on a database key.edit: example - note the database handling routines are proprietary and you'd have to put in your own. The rest of the handler will show how to rescale images (if desired) and send back as a response to the browser:
数据uri字符串长度是多少,根据数据协议IE8 数据 URI 不能大于 32,768 个字符。
编辑:资源数据必须正确编码;否则会出错,资源不会加载。必须对“#”和“%”字符以及控制字符、非 US ASCII 字符和多字节字符进行编码。
What is data uri string length, according to data Protocol in IE8 Data URIs cannot be larger than 32,768 characters.
Edit: The resource data must be properly encoded; otherwise, an error occurs and the resource is not loaded. The "#" and "%" characters must be encoded, as well as control characters, non-US ASCII characters, and multibyte characters.