Results 1 to 2 of 2

Thread: ASP.NET - return a code drawn image

  1. #1

    Thread Starter
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    ASP.NET - return a code drawn image

    This is an example of how to make an .aspx page return an image, so that you can do for example (IMG SRC='\codepage.aspx' /), you probably came here from the link in my signature so no more explanation required

    and if not (or if ive removed it, this is it):


    Ok, so the code that makes that page is this(on the load event):
    Code:
            'use GDI+ to crate a bitmap canvas and graphics
            Dim bit As New Bitmap(300, 15)
            Dim g As Graphics = Graphics.FromImage(bit)
            g.Clear(Color.FromArgb(241, 241, 241)) 'using forums colour
            'draw something o nthe bitmap
            g.DrawString("Your IP is: " & Me.Request.UserHostAddress & "  <- learn how", New Font(FontFamily.GenericSansSerif, 10, FontStyle.Underline), New SolidBrush(Color.Blue), 0, 0)
    
            'wipe out return content (which is normally a webform)
            Me.Response.ClearContent()
            Me.Response.ClearHeaders()
            'make response type an image (and we're going to use a PNG)
            Me.Response.ContentType = "image/png"
    
            'make a memorystream to put the image bytes into
            Dim temp As New IO.MemoryStream
            'save the image to the memorystream
            bit.Save(temp, Imaging.ImageFormat.Png)
            'write the bytes from our memory stream, to the response of our webpage (so send it to the browser)
            Me.Response.BinaryWrite(temp.ToArray)
            'finish up
            Me.Response.End()
    Enjoy.
    Last edited by Phill64; May 15th, 2007 at 12:58 PM.

  2. #2
    Member
    Join Date
    Apr 2006
    Posts
    34

    Re: ASP.NET - return a code drawn image

    Quote Originally Posted by Phill64
    This is an example of how to make an .aspx page return an image, so that you can do for example (IMG SRC='\codepage.aspx' /), you probably came here from the link in my signature so no more explanation required

    and if not (or if ive removed it, this is it):


    Ok, so the code that makes that page is this(on the load event):
    Code:
            'use GDI+ to crate a bitmap canvas and graphics
            Dim bit As New Bitmap(300, 15)
            Dim g As Graphics = Graphics.FromImage(bit)
            g.Clear(Color.FromArgb(241, 241, 241)) 'using forums colour
            'draw something o nthe bitmap
            g.DrawString("Your IP is: " & Me.Request.UserHostAddress & "  <- learn how", New Font(FontFamily.GenericSansSerif, 10, FontStyle.Underline), New SolidBrush(Color.Blue), 0, 0)
    
            'wipe out return content (which is normally a webform)
            Me.Response.ClearContent()
            Me.Response.ClearHeaders()
            'make response type an image (and we're going to use a PNG)
            Me.Response.ContentType = "image/png"
    
            'make a memorystream to put the image bytes into
            Dim temp As New IO.MemoryStream
            'save the image to the memorystream
            bit.Save(temp, Imaging.ImageFormat.Png)
            'write the bytes from our memory stream, to the response of our webpage (so send it to the browser)
            Me.Response.BinaryWrite(temp.ToArray)
            'finish up
            Me.Response.End()
    Enjoy.
    hi,

    Did you try this code in .net 2005?

    tnx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width