ListView Image

0

Difficulty: Display an image in the template item of the List View control. The datasource property of the control is populated with a collection. In the collection, the image returns from the SQlServer as an array of bytes. So I need to convert it to an image in the control template item.

         <ItemTemplate>
                <h2><%#Eval("titulo")%></h2>                                                                                                                      
                <p><h5><%#Eval("texto")%></h5></p>                                             
                <h6><%#Eval("data", "{0:d}")%></h6>   
                imagem convertida aqui
        </ItemTemplate>     
    
asked by anonymous 03.10.2015 / 01:26

1 answer

0

To get an Image as a return, see if the code below helps you:

public Image byteArrayToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(ms); return returnImage; }

If you prefer a BitmapImage:

public BitmapImage ImageFromBuffer(Byte[] bytes) { MemoryStream stream = new MemoryStream(bytes); BitmapImage image = new BitmapImage(); image.BeginInit(); image.StreamSource = stream; image.EndInit(); return image; }

    
03.10.2015 / 18:15