I am trying to display an image (byte array) using purely JavaScript.
How can I achieve this in ASP.NET?
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.
//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.
Images are binary data - this is easily represented as byte arrays. The image in the sample is stored in the database as a BLOB - not a string or location, that is, it is binary data.
The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. It is an array of bytes, often referred to in other languages as a "byte array".
If you have the byte array, you first convert it to Base64String
and then you place it on an img
tag like that (for a PNG image):
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot">
Similar Stack Overflow questions:
Display bytes as images on an .aspx page
'data:image/jpg;base64' and jQuery image preview in Internet Explorer
Convert from binary data to an image control in ASP.NET
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