1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP text to image

Discussion in 'C#' started by ludwig, May 28, 2006.

  1. #1
    I have a problem of creating a dynamic image which will be real time updated and will show the number of visits to the site, with a logo,

    I dont want to have a frame there.

    How can I convert the HTML structure of the banner to an image? is it possible to do that without using any DLLs etc?
     
    ludwig, May 28, 2006 IP
  2. benjymouse

    benjymouse Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Make a handler called ImageLabel.ashx (this is just a sample of one, untested):

    <%@ WebHandler Language="C#" Class="ImageLabel" %>
    
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Web;
    
    public class NumberImage : IHttpHandler
    {
    
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/gif";
    
            Size sz = new Size(200, 30);
            using (Image img = new Bitmap(sz.Width, sz.Height))
            using (Graphics g = Graphics.FromImage(img))
            {
                g.FillRectangle(Brushes.White, 0, 0, sz.Width, sz.Height);
                g.DrawString(
                    context.Request.QueryString["str"],
                    new Font("Arial", 18),
                    Brushes.Blue,
                    new RectangleF(Point.Empty, img.Size));
                img.Save(context.Response.OutputStream, ImageFormat.Gif);
            }
        }
    
        public bool IsReusable
        {
            get { return true; }
        }
    
    }
    Code (markup):


    Reference it like this:

    ImageLabel.ashx?str=Text+to+write
    Code (markup):
     
    benjymouse, May 29, 2006 IP
  3. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #3
    Thanks benjymouse

    but the code doesn't work on my local PC, haven't tried on my web server, but there shouldn't be any difference between the two PCs.

    I know there is a way with PHP, but haven't found the solution for ASP
     
    ludwig, May 29, 2006 IP