开发者

Byte array output as an Image

开发者 https://www.devze.com 2022-12-08 12:26 出处:网络
I know it is be possible to do this: <asp:Image runat=\"server\" ImageUrl=\"~/MyImageHandler.ashx?imageid=2\" />

I know it is be possible to do this:

<asp:Image runat="server" ImageUrl="~/MyImageHandler.ashx?imageid=2" />

...but I have a case where the byte array data is only available to the Page (ie, not available in the session, and cannot be referenced by an id) so I can't point the ImageUrl to a different page.

Is there a w开发者_运维技巧ay of giving an asp:Image the byte array to render as an Image?


The major hurtle you're going to have to deal with is that an <asp:Image/> element gets rendered as a regular <img />, which needs a src attribute that points at a URL.

That being the case, I see two hairy alternatives:

  • Use the technique described here to embed your image encoded in Base64 in the src attribute. Note that this does not work with Internet Explorer.

  • Embed your Base64-encoded image into the page as a hidden <input /> element. You could then use JavaScript to POST that data back to the server, which would just send it back to the browser using Response.Write() (being sure to set the Content-Type appropriately, of course).


The only decent solution to this is to put the byte array in session. If you're concerned about uniqueness (multiple people getting each other's byte arrays), use a random GUID as the key.

0

精彩评论

暂无评论...
验证码 换一张
取 消