Can you render and image in ASP.NET?

Discussion in 'ASP .Net' started by Lars Netzel, Jan 5, 2005.

  1. Lars Netzel

    Lars Netzel Guest

    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
     
    Lars Netzel, Jan 5, 2005
    #1
    1. Advertising

  2. What do you mean? The browser renders the images, the server just provides
    the path in the form of HTML.

    "Lars Netzel" <> wrote in message
    news:#...
    > 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
    >
    >
     
    Peter Rilling, Jan 5, 2005
    #2
    1. Advertising

  3. Lars Netzel

    Lars Netzel Guest

    No I mean dynamically creating images.. for example images that needs
    language support and stuff like that. I heared a long time ago abot usoem
    GIF creator that was part of .NET but I've never seen it...

    /lars


    "Peter Rilling" <> skrev i meddelandet
    news:...
    > What do you mean? The browser renders the images, the server just
    > provides
    > the path in the form of HTML.
    >
    > "Lars Netzel" <> wrote in message
    > news:#...
    >> 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
    >>
    >>

    >
    >
     
    Lars Netzel, Jan 5, 2005
    #3
  4. > Is there any possibility to render images for the web in asp.net?

    Yup.

    > Is it hard?


    Not for me. Probably for some people. I can't speak for them.

    > Is there something built in or do I need external commercial components?


    Everything you need is in the CLR. The System.Drawing and
    System.Drawing.Imaging namespaces contain all the functionality you need,
    combined with, of course, ASP.Net classes.

    The first thing you need to do is define what you want to render. If you
    want to open an image from a file, or if you want to draw one dynamically.

    You would need to create an ASPX page that serves as the "image." You would
    link to it as you would any other image, with an HTML image tag. The ASPX
    page then creates the image (however), sets the Response.ContentType to
    "image/jpg" (or whatever image type you're returning), and then saves the
    image to the Response.OutputStream.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Neither a follower nor a lender be.

    "Lars Netzel" <> wrote in message
    news:%...
    > 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
    >
     
    Kevin Spencer, Jan 5, 2005
    #4
  5. Ken Cox [Microsoft MVP], Jan 5, 2005
    #5
  6. Lars Netzel

    John Puopolo Guest

    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" <> wrote in message news:%...
    > 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
    >
    >
     
    John Puopolo, Jan 5, 2005
    #6
  7. Lars Netzel

    Lars Netzel Guest

    Nice, thanx!

    /Lars

    "John Puopolo" <> skrev i meddelandet
    news:...
    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" <> wrote in message
    news:%...
    > 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
    >
    >
     
    Lars Netzel, Jan 5, 2005
    #7
  8. Lars Netzel

    Lars Netzel Guest

    Thank you, that example got me started quite fast... great!

    /Lars


    "Ken Cox [Microsoft MVP]" <> skrev i meddelandet
    news:%...
    > Hi Lars,
    >
    > There's lots you can do with System.Graphics to create images in memory in
    > ASP.NET:
    >
    > http://aspalliance.com/articleViewer.aspx?aId=400&pId=1
    >
    > http://authors.aspalliance.com/chrisg/tools/view-imagecounter.asp
    >
    > Ken
    >
    >
    >
    > "Lars Netzel" <> wrote in message
    > news:%...
    >> 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
    >>

    >
     
    Lars Netzel, Jan 5, 2005
    #8
  9. Lars Netzel

    Lars Netzel Guest

    follow up question

    Do I need to have this in an Aspx page? Is there other ways to call for the picture? I want to do this all in one class.

    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.

    /Lars
    "John Puopolo" <> skrev i meddelandet news:...
    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" <> wrote in message news:%...
    > 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
    >
    >
     
    Lars Netzel, Jan 5, 2005
    #9
  10. Re: follow up question

    Remember that on thg client, its all HTML. The main point is that you need
    an image tag that points to the ASPX page that generates the image. It
    doesn't matter if that image tag is in a Control or any other element in an
    ASPX page. And, of course, you can request the ASPX page that generates the
    image all by itself, just as you would request an image from a web server
    all by itself.

    In other words, you treat the ASPX page that generates the image as if it
    WERE an image, in whatever context you use it. To the browser, it will BE an
    image, due to the Response.ContentType.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Neither a follower nor a lender be.

    "Lars Netzel" <> wrote in message
    news:es%...
    Do I need to have this in an Aspx page? Is there other ways to call for the
    picture? I want to do this all in one class.

    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.

    /Lars
    "John Puopolo" <> skrev i meddelandet
    news:...
    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" <> wrote in message
    news:%...
    > 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
    >
    >
     
    Kevin Spencer, Jan 6, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,094
    Lau Lei Cheong
    May 15, 2004
  2. Steve Gelfmann

    Can't render User Control in an ASP.NET page

    Steve Gelfmann, Jun 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    599
    Lau Lei Cheong
    Jun 21, 2004
  3. =?Utf-8?B?ZG9uanVhbg==?=
    Replies:
    1
    Views:
    2,509
    Brock Allen
    Aug 17, 2005
  4. Support
    Replies:
    1
    Views:
    468
    Steve C. Orr [MVP, MCSD]
    Jun 3, 2005
  5. Glenn Gillen
    Replies:
    0
    Views:
    288
    Glenn Gillen
    Nov 17, 2006
Loading...

Share This Page