asp:Image from sqlserver image

 




            <asp:Image ID="Image2" runat="server" />


                                byte[] imgArray = (byte[])reader["Photo"];

                                Image2.ImageUrl = "data:image;base64," + Convert.ToBase64String(imgArray);



ref https://stackoverflow.com/questions/39338359/asp-net-display-image-from-byte-array

Another way to do it is to convert your byte array into a base 64 string and assign that to the ImageUrl property of rImage, like so:

rImage.ImageUrl = "data:image;base64," + Convert.ToBase64String(arr);

You don't need the intermediate MemoryStream or a separate page...if the byte array is in an image format the browser supports, it will display. Good luck.


留言

熱門文章