On my Form Load event I am creating a bitmap using System.Drawing classes, and I want to display this image on my WebForm. How can I do that?
开发者_JAVA百科Thanks!
You can't create this bitmap directly in your webform. You will need to implement custom HttpHandler
that will render this image separately.
- Serving Dynamic Content with HTTP Handlers
- HTTP Handlers for Images in ASP.NET
- Use Custom HTTP Handlers in Your ASP.NET Applications
Instead of creating the image in the code behind for your page, what you should do is create a URL for the image that somehow describes or defines the image's content (perhaps along with session state or a cookie if you need to), and attach that URL to a regular <img>
(or <asp:Image>
) tag.
Then, when the browser requests that URL, your code determines the parameters from the query string or cookies or whatever, generates and sends the response, and returns it with the correct MIME type. That's usually best done from a Generic HttpHandler (*.ashx).
精彩评论