Display bytes as images on .aspx page

I use a database to store client images in bytes. How can I make these images on an .aspx page?

+9
html image
Aug 07 '10 at 16:09
source share
3 answers

Two solutions.

  • Create a handler page. This takes the ImageID / RowID parameter as GET and returns the data using mimetype image / jpeg or image / png.

  • Use the DATA uri scheme as described in wikipedia .

    <Img src = "data: image / png; base64, iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs + 9AAAABGdBTUEAALGP C / xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd 0SU1FB9YGARc5KB0XV + IA AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq CH9 // q1uH4TLzw4d6 + ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0 vr4MkhoXe0rZigAAAABJRU5ErkJggg ==" alt = "Red dot" />

+27
Aug 07 '10 at 16:14
source share

Instructions can be found here: http://www.dotnetcurry.com/ShowArticle.aspx?ID=129&AspxAutoDetectCookieSupport=1

in step 4, but the whole article is worth reading.

+2
Aug 7 '10 at 16:11
source share

This can be done easily by converting the byte array into a Base64 image.

public string GetImageAsBase64String(byte[] bin) { if (bin != null) { return "<img src=\"data:image/jpeg;base64," + Convert.ToBase64String(bin) + "\">"; } else { return null; } } //usage, for demo purposes an uploaded image from a FileUpload Control Label1.Text = GetImageAsBase64String(FileUpload1.FileBytes); 
+1
Mar 31 '17 at 11:51
source share



All Articles