2

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.