Obtaining Graphics Object

Discussion in 'ASP .Net' started by jediknight, Jul 18, 2006.

  1. jediknight

    jediknight Guest

    Hi,

    I am designing a web form which as an imagemap. I need to obtain a
    graphics object so I can draw on this imagemap.

    Can anyone tell me how to do this?

    I have tried creating a bitmap object and doing Graphics.FromImage call
    but the image on the imagemap disappears leaving a black background.


    Many thanks in advance!!
    jediknight, Jul 18, 2006
    #1
    1. Advertising

  2. I'm not sure how you intend to draw on a web page? You are talking about
    the server generating a bunch of HTML to send to the client. The server
    cannot draw something in the client browser drawing surface.

    Perhaps I am misunderstanding what you are trying to do.

    "jediknight" <> wrote in message
    news:...
    > Hi,
    >
    > I am designing a web form which as an imagemap. I need to obtain a
    > graphics object so I can draw on this imagemap.
    >
    > Can anyone tell me how to do this?
    >
    > I have tried creating a bitmap object and doing Graphics.FromImage call
    > but the image on the imagemap disappears leaving a black background.
    >
    >
    > Many thanks in advance!!
    >
    Marina Levit [MVP], Jul 18, 2006
    #2
    1. Advertising

  3. jediknight

    Kelly Herald Guest

    Do the following:

    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(50, 100,
    System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);


    What you will most likely want to do is create a Generic Handler (*.ashx) to
    do the drawing. If you use the ASHX approach then when you are done drawing
    then just output the bitmap to the OutputStream.

    bmp.Save(context.Response.OutputStream,
    System.Drawing.Imaging.ImageFormat.Jpeg);

    On your ASPX page the source URL for the image will be the path to the ASHX
    file.

    Sample code:

    Image.ashx
    using System;
    using System.Web;


    public class Image : IHttpHandler
    {

    public void ProcessRequest (HttpContext context)
    {
    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(50, 100,
    System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

    g.Clear(System.Drawing.Color.Blue);

    bmp.Save(context.Response.OutputStream,
    System.Drawing.Imaging.ImageFormat.Jpeg);
    }

    public bool IsReusable
    {
    get
    {
    return false;
    }
    }

    }

    Default.aspx
    <img src="Image.ashx" />


    "jediknight" <> wrote in message
    news:...
    > Hi,
    >
    > I am designing a web form which as an imagemap. I need to obtain a
    > graphics object so I can draw on this imagemap.
    >
    > Can anyone tell me how to do this?
    >
    > I have tried creating a bitmap object and doing Graphics.FromImage call
    > but the image on the imagemap disappears leaving a black background.
    >
    >
    > Many thanks in advance!!
    >
    Kelly Herald, Jul 19, 2006
    #3
    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. John Nagle
    Replies:
    11
    Views:
    632
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Dec 14, 2006
  2. Replies:
    1
    Views:
    387
  3. Nathan Duran
    Replies:
    1
    Views:
    337
    Arnaud Delobelle
    Apr 10, 2008
  4. SamG
    Replies:
    1
    Views:
    238
    Terry Reedy
    Aug 7, 2008
  5. Mrinalini Kulkarni
    Replies:
    0
    Views:
    187
    Mrinalini Kulkarni
    Dec 25, 2011
Loading...

Share This Page