将图像转换为数据:image / png; base64用于网页disaplay [英] Converting image into data:image/png;base64 for web page disaplay

查看:309
本文介绍了将图像转换为数据:image / png; base64用于网页disaplay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人访问 jQuery文件上传演示页面,并尝试上传一个图像,然后会看JSON响应,他会注意到,上传的图像的预览将以以下格式返回:

If one visits jQuery-File-Upload Demo page and will try to upload an image, and then will look at the JSON response, he would notice that a preview of an uploaded image is returned in a format:

"thumbnail_url":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAI...

据我所知,一个图像被转换成字符串并发送回客户端。

As far as I understand, an images is getting transformed into string and sent back to the client.

我如何在C#中将ASP.NET的后端修改为相同的演示?

How can I do it in C# to impelement ASP.NET back end for the same demo?

推荐答案

我记得看到一个问题的答案,一个很好的能力的技术人员,思考我从来不知道你可以这样做!

I remember reading an answer to a question a while back by the very competent competent_tech and thinking "I never knew you could do that!"

在这个答案是一个例子关于如何将ASP.Net映像的src设置为上面看到的base64编码数据。

In that answer is an example about how to set the src of an ASP.Net image to be the base64 encoded data you see above.

它有效地归结为如下设置ASP:图像控件的src:

It effectively boils down to setting the src of an ASP:Image control as follows:

imgCtrl.Src = @"data:image/gif;base64," + Convert.ToBase64String(File.ReadAllBytes(Server.MapPath(@"/images/your_image.gif")));

请记住根据图像更改内容类型!

Remember to change the content type depending on the image!

这篇关于将图像转换为数据:image / png; base64用于网页disaplay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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