[英]Converting image into data:image/png;base64 for web page disaplay
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: 如果访问jQuery-File-Upload Demo页面并尝试上传图像,然后查看JSON响应,他会注意到以下格式返回上传图像的预览:
"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. 据我了解,图像正在转换为字符串并发送回客户端。
How can I do it in C# to impelement ASP.NET back end for the same demo? 如何在C#中为相同的演示阻止ASP.NET后端?
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!" 我记得在一段时间内,非常称职的competent_tech回答了一个问题的答案,并且“我从来不知道你能做到这一点!”
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.Net映像的src设置为您在上面看到的base64编码数据的示例 。
It effectively boils down to setting the src of an ASP:Image control as follows: 它有效地归结为设置ASP的src:Image控件如下:
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! 请记住根据图像更改内容类型!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.