How to display byte image on asp.net page dynamically?

I uploaded a byte array image from a web service to my asp.net site. I need to display it on a web page right after the web service runs.

I tried using a common handler, but I could not do this, because there was no way to pass the image of byte [] to a common handler

void Button2_Click1(object sender, EventArgs e) { this.verifyTemplates(); byte[] userImg; try { matchTemp.templateService hs = new matchTemp.templateService(); bool s1 = hs.matchTemplates(template, out userID, out userName, out userImg); // userImg is the byte image i need to display } catch(Exception exc) { // vLabel.Text = exc.Message; } } 
+4
source share
1 answer

What you are looking for is the data url . You can get a base64 byte array like this (change the image type as needed)

 string imageBase64 = Convert.ToBase64String(userImg); string imageSrc = string.Format("data:image/gif;base64,{0}", imageBase64); 

In view:

 <img src='"<%=imageSrc%>"' /> 

This will not work in IE 7 or earlier, if you need to support them then you will want to look at MHTML .

+4
source

Source: https://habr.com/ru/post/1403060/


All Articles