views:

66

answers:

3

Hi,

I use to store client Images in DB in bytes, the problem is how can I render that image on .aspx page

Thanks

+1  A: 

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

in step 4, but the whole article is worth a read.

David Stratton
+3  A: 

Two solutions.

  1. Build a handler page. That takes an ImageID/RowID as GET parameter and returns data with mimetype image/jpeg or image/png.

  2. Use DATA uri scheme as explained on wikipedia.

    <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0 vr4MkhoXe0rZigAAAABJRU5ErkJggg==" alt="Red dot" />

Ankit Jain
Nice.. I'd never heard of the DATA uri sheme. +1 to you. That's why I love this site.. Something new every day...
David Stratton
@david - even I knew very late in my career. i had belief only file paths are allowed there.
Ankit Jain
@ankit +1, ditto @David. Never heard of it; will solve a big, huge problem for me: pre-downloading png images. CSS classes that incorporate base-64-encoded images will (I think!) be much quicker, more reliable, and more repeatable than other well-known but imo somewhat ugly, hackish pre-downloading schemes.
Pete Wilson
@lcplben.. ooh ya. this is ugly as these images are never cached and travel with page content. Not good for bigger images. And do not use second method for the sake of PRE-LOADING images.
Ankit Jain
@Ankit thanks for reply..is we have to use data:image/png;base64 for every image byte array?
BreakHead
here is what I am trying to System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); investorLogo.Src = string.Format("data:image/png;base64,{0}", enc.GetString(investor.Logo));but its rendering all bytes
BreakHead
Hey its working.....
BreakHead