I have a byte array and trying to display image from that.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Linq;
namespace RealPortableTerminal
{
public partial class resim : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
PortableTerminalDbEntities entity = new PortableTerminalDbEntities();
byte[] arr = (from b in entity.Sicil where b.Id == 31 select b.Fotograf).First();
Image rImage = null;
using (MemoryStream ms = new MemoryStream(arr))
{
rImage = Image.FromStream(ms);
}
}
}
}
It underlines FromStream and says 'System.Web.UI.WebControls.Image' does not contain a definition for 'FromStream'. It seems adding System.Data.Linq reference did not changed anything. Am I missing something ? Btw I am pretty sure I take byte array from database correctly.
//ImageConverter Class convert Image object to Byte Array. byte[] bytes = (byte[])(new ImageConverter()). ConvertTo(img, typeof(byte[])); //Convert Byte Array to Image and display in PictureBox.
whole bytes (24 bits) are used to represent the colour of each pixel. This is split up into one byte for each of the primary colours of light, red, green and blue. This is because computer displays uses these primary colours of light to display all the different colours we see on the screen.
<img id="img" runat="server" alt=""/>
In code behind
string base64String = Convert.ToBase64String(arr, 0, arr.Length);
img.Src = "data:image/jpg;base64," + base64String;
You wouldn't need MemoryStream
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With