I need to create some block diagrams on my ASP.NET page. Is it best done 开发者_如何转开发by drawing on Bitmap
? How to display this dynamically generated Bitmap
object?
Create a http handler that writes the bitmap to the response stream.
Heres a link on handlers themselves http://www.dotnetperls.com/ashx.
If you can write a file to the file system, using some form of naming convention, so that your not generating it over and over again.
If you have it written to a file you can write that to the response stream using context.Response.WriteFile(path);
You'll need to set appropriate headers for the response if you want to cahce something like the below should be ok.
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetLastModified(lastWrite);
context.Response.Cache.SetETag(string.Format("\"{0}\"", lastWrite.Ticks));
context.Response.ContentType = "image/png";
you can check these headers on an incoming request and return a 304 with something like (do a null check before)
if (context.Request.Headers[since] >= lastwrite || context.Request.Headers[eTag] >= lastwriteTicks) {
context.Response.StatusCode = 304;
context.Response.StatusDescription = "Not Modified";
return;
}
If you need to generate fresh every time dont worry about caching and just write your iamge to the context.Response.OutputStream
.
精彩评论