Convert byte to image using <img src>

Asked

Viewed 918 times

0

To convert a byte that comes from the sql database into image in Listview I do so:

        <asp:Image runat="server" ID="Image1" CssClass="image1style" 
        ImageUrl='<%# "data:image/jpg;base64,"+ 
        Convert.ToBase64String((byte[])Eval("imagem1")) %>'/>

I’d like to do the same thing but using

        <img src= " " ...

It worked that way:

 <img runat="server" ID="Img1" src = '<%# "data:image/jpg;base64," 
  + Convert.ToBase64String((byte[])Eval("imagem1")) %>'
  • What is that imagem1 within the Eval?

  • @jbueno is the table field that contains the byte array (image). I was able to solve this problem by simply replacing the control with <img and repeating the rest.

1 answer

-1

I believe you can manage using a script :

Html

<img id="MinhaImagem" src="" />

Script

document.getElementById("MinhaImagem").src = "data:image/png;base64," + Bytes;
  • I tried it like this, I couldn’t.

  • Gives error ? Is migrating a service in ASP.NET Webforms to Html5 ?

  • does not give error, simply does not occur as expected, IE, the control does not display the image.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.