Is there anyway to display a dynamically generated bitmap on an asp control?

In my code, I create a bitmap dynamically using C # and ASP.NET. Then I need to display it on an asp image control. Is there any way to do this without using handlers?

+8
c # image controls bitmap
source share
1 answer

Using the ashx handler is better because it works in all browsers and you can cache output images on the client.

However, if you must do this, images can be displayed in a line directly using the <img> as follows:

 <img src="data:image/gif;base64,<YOUR BASE64 DATA>" width="100" height="100"/> 

Aspx:

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

CS:

 MemoryStream ms = new MemoryStream(); bitmap.Save(ms, ImageFormat.Gif); var base64Data = Convert.ToBase64String(ms.ToArray()); imgCtrl.Src = "data:image/gif;base64," + base64Data; 

Yes, you can write a bitmap directly, but compressed formats (JPEG, GIF) are better for the Internet.

Note. Embedded images do not work in older browsers. Some versions of IE had restrictions on the maximum size of 32 KB.

+16
source share

All Articles