Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bytearray to image asp.net

Tags:

I have a byte array representing a picture. I want to present the picture stored in that byte array in an aspx page. Can I do it using an image or imagemap control? If so - how? If not - what's the solution?

like image 373
user181218 Avatar asked Nov 15 '09 16:11

user181218


People also ask

How do I create a byte array image?

Create a ByteArrayInputStream object by passing the byte array (that is to be converted) to its constructor. Read the image using the read() method of the ImageIO class (by passing the ByteArrayInputStream objects to it as a parameter). Finally, Write the image to using the write() method of the ImageIo class.

What does mean Bytearray?

A byte array is simply an area of memory containing a group of contiguous (side by side) bytes, such that it makes sense to talk about them in order: the first byte, the second byte etc..


1 Answers

Another thing you can do which is quicker would be to not use the asp.net Image control and use the basic img element in html. So within your asp.net page, create a img element with an id of img and runat set to server.

Then you could do something like this:

<img id="img" runat="server" alt=""/>

public DataRow ClaimPhotoRow { get; set; } protected void Page_Load(object sender, EventArgs e) {     img.Src = "data:image/jpg;base64," + Convert.ToBase64String((byte[])ClaimPhotoRow[0]);  } 
like image 153
Jay Stratemeyer Avatar answered Oct 21 '22 23:10

Jay Stratemeyer