Converting image into data:image/png;base64 for web page disaplay

后端 未结 1 889
暖寄归人
暖寄归人 2020-12-05 04:55

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 r

相关标签:
1条回答
  • 2020-12-05 05:43

    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!"

    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.

    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!

    0 讨论(0)
提交回复
热议问题