I have saved an image in MSSQL server database using the IMAGE format. It shows as bytes from the database, I want to convert that byte stream to image in HTML and display that.
I have followed this tutorial. It shows as Image even though tutorial describes it will display the Image properly it shows Only the "Image" instead of an actual image file.
<td>
@{ byte[] photo = item.image;
string imageSrc = null;
if (photo != null)
{
MemoryStream ms = new MemoryStream();
ms.Write(photo, 78, photo.Length - 78);
string imageBase64 = Convert.ToBase64String(ms.ToArray());
imageSrc = string.Format("data:image/jpeg;base64,{0}", imageBase64);
}
}
<img src="@imageSrc" alt="Image" />
</td>
Output of the code
Rendered Result Source