Re: Can you render and image in ASP.NET?

From: Lars Netzel (troligt_at_apa.se)
Date: 01/05/05


Date: Wed, 5 Jan 2005 23:07:55 +0100

Nice, thanx!

/Lars

"John Puopolo" <john.puopolo@fastsearch.com.nospam> skrev i meddelandet
news:OBfsDG38EHA.3700@tk2msftngp13.phx.gbl...
Hi...

Yes, you can create an image dynamically in ASP.NET. It's fairly straight
forward as well.

The idea is to create an image in memory on the server and stream it back to
the client (browser). Now, *if* you were to write that image to disk, you
could insert an <img> tag in the output stream and provide a link back to
the newly created image that you saved off; however, since you want to send
the image bytes back to the browser, you will need an <img> tag in the page
HTML whose source is the ASPX page that constructs the image. For example:

<html>
This is some text.
<img src="genImage.aspx">
Isn't that a pretty picture?
</html>

Now, the genImage.aspx code simply uses the System.Drawing, etc. to render
an image. Here is a simple example from a sample project I have:

>From genImage.aspx:
private void Page_Load(object sender, System.EventArgs e) {
    Bitmap objBitmap = new Bitmap(200, 200);
    Graphics g = Graphics.FromImage(objBitmap);
    g.FillEllipse(Brushes.Red, 0, 0, 200, 200);
    objBitmap.Save(Response.OutStrean, ImageFormat.Gif);
}

That's it. You have the full power of the .NET drawing and image libraries
at your disposal and can generate as complex an image as you can dream up.

Enjoy...

John Puopolo

"Lars Netzel" <troligt@apa.se> wrote in message
news:%23p1QcI28EHA.208@TK2MSFTNGP12.phx.gbl...
> Hey!
>
> Is there any possibility to render images for the web in asp.net? Is it
> hard? Is there something built in or do I need external commercial
> components?
>
> best regards
> /Lars
>
>



Relevant Pages

  • Re: OT: HTML (WAS: MF having issues?)
    ... Right, the example above, with the tag, comes from web developers inapporpriately depending on undocumented features. ... But let's say I don't actually read the standards, but just try out the tag to see what it does, and I notice that on my particular browser, the tag displays the text in italics. ... So now my HTML page may be broken, for example, if it contained text like this: ...
    (comp.lang.cobol)
  • Re: OT: HTML (WAS: MF having issues?)
    ... But let's say I don't actually read the standards, but just try out the tag to see what it does, and I notice that on my particular browser, the tag displays the text in italics. ... So now my HTML page may be broken, for example, if it contained text like this: ... The idea is that browsers who do not recognize the <applet> tag will simply ignore that tag, and display the text without any special formatting. ...
    (comp.lang.cobol)
  • Re: java detection test on a webpage with applet
    ... the applet cannot be displayed in this browser. ... My understanding of HTML ... is that if the browser doesn't recognize a tag, it simply ignores it, so ...
    (comp.lang.java.help)
  • Re: Tail a logfile to a web page
    ... > different techniques usable with a web browser. ... A HTML interface ... The page will refresh every nn seconds. ... REFRESH is not a tag. ...
    (comp.infosystems.www.authoring.html)
  • Re: Simple question ??
    ... A web page is basically an HTML document. ... a technology that, at the most basic level, delivers HTML to a web browser. ... Internet Explorer, for example, can display Word documents, ... file format to a browser in its native state. ...
    (microsoft.public.dotnet.framework.aspnet)