图像转换成数据:图像/ PNG;对于网页disaplay的base64 [英] Converting image into data:image/png;base64 for web page disaplay
问题描述
如果人访问 jQuery的,文件的上传演示页并会尽量上传图片,然后会看JSON响应,他会注意到上传图像的preVIEW的格式返回:
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?
推荐答案
我记得以前看过一个问题的答案回,而由非常能干competent_tech和思考:我从来不知道你能做到这一点!
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恩您在上面看到codeD数据。
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:Image控件如下:
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!
这篇关于图像转换成数据:图像/ PNG;对于网页disaplay的base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!