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

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: John Puopolo (john.puopolo_at_fastsearch.com.nospam)
Date: 01/05/05

  • Next message: laks: "Request has timed"
    Date: Wed, 5 Jan 2005 16:57:12 -0500
    
    

    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
    >
    >


  • Next message: laks: "Request has timed"

    Relevant Pages

    • Re: Can you render and image in ASP.NET?
      ... the client (browser). ... the image bytes back to the browser, you will need an tag in the page ... HTML whose source is the ASPX page that constructs the image. ... > Is there any possibility to render images for the web in asp.net? ...
      (microsoft.public.dotnet.framework.aspnet)
    • follow up question
      ... I guess the ContentType is pretty important but I'm wanting to do an output from a WebControl that also generates the picture. ... That means I won't have any aspx page avaliable. ... 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. ... > Is there any possibility to render images for the web in asp.net? ...
      (microsoft.public.dotnet.framework.aspnet)