反正有一个asp的图像控件中显示动态生成位图? [英] Is there anyway to display dynamically generated Bitmap on a asp image control?
问题描述
在我的code动态地创建位图,使用C#和ASP.NET。比我需要显示它的ASP图像控制。有反正做使用内部消除处理?
In my code I create a bitmap dynamically, using c# and ASP.NET. Than I need to display it on the asp image control. There are anyway to do it whithout using handlers?
推荐答案
使用ASHX处理程序是更加美好的事业它适用于所有的浏览器,你可以在客户端缓存的输出图像。
Using a ashx handler is better cause it works on all browsers and you can cache the output images on the client.
然而,如果你必须这样做,可以显示图像内嵌直接使用< IMG>
标记,如下所示:
However if you must do it, images can be displayed inline directly using the <img>
tag 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;
是的,你可以直接写位图,但COM pressed格式(JPEG,GIF)是用于Web越好。
Yes, you could write the bitmap directly, but compressed formats(JPEG, GIF) are better for the web.
注意:内嵌图像不起作用在旧的浏览器。 IE浏览器的某些版本有32KB的最大尺寸的限制。
Note: Inline images don't work on older browsers. Some versions of IE had limitations of max 32KB size.
这篇关于反正有一个asp的图像控件中显示动态生成位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!