Print Page | Close Window

Images ’on the fly’

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=2464
Printed Date: 28 March 2026 at 3:11pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Images ’on the fly’
Posted By: Mart
Subject: Images ’on the fly’
Date Posted: 06 May 2003 at 9:14am

Hi, I have a script that creates custom graphics

(using the normal <img> tag),

i.

Is it possible to make this inside of the letters be filled with a colour (I only know how to do the line)

ii.

Is it possible to have a drop shadow..

here is the code I use:

<% @Page Language="VB" %>
    <% @Import Namespace="System.Drawing" %>
    <% @Import Namespace="System.IO" %>
    <% @Import Namespace="System.Drawing.Imaging" %>
    <%
    Response.Expires = 0
    Dim newBitmap as Bitmap '= null
    Dim g as Graphics '= null
    Dim sFont as string
    Dim sFontSize as string
    Dim sPhrase as string
    Dim iFontSize as integer
    Dim sColorBackground as string
    Dim oColorBackground as color
    Dim sFontColorName as string
    dim ofont as color
    Dim oFontColor as color
    Dim oFontCounter as font
    Dim oBitMap as bitmap
    Dim oStream as MemoryStream
    dim oStringSize as SizeF
    Dim iWidth as integer
    Dim iHeight as Integer
    Dim oBitmapOut as bitmap
   
    ' Get the phrase to render
    sPhrase = Request.QueryString.Get("Phrase")
    'if sPhrase = Null then str2Render = "No Phrase specified"
   
    ' What font should we use?
    sFont = Request.QueryString.Get("FontName")
    'if sFont = Null Then sFont = "Lucida Sans Unicode"
   
    ' Which font size?
    iFontSize = 12
    sFontSize = Request.QueryString.Get("FontSize")
    'if NOT (sFontSize = NULL) Then
        iFontSize = convert.toint32(sFontSize)
    'End If
   
    ' How about a different background color
    sColorBackground = Request.QueryString.Get("BackgroundColor")
    oColorBackground = Color.White
    'if NOT (sColorBackground = NULL) then
          oColorBackground = ColorTranslator.FromHTML(sColorBackground)
    'end if
   
    ' Should we change the font color?
    sFontColorName = Request.QueryString.Get("FontColor")
    oFont = Color.Black
    'if NOT (sFontColorName = NULL) Then
        oFont = ColorTranslator.FromHTML(sFontColorName)
    'End If
   
    ' Get measurements of the image based on Font Size
    oFontCounter = new Font(sFont, iFontSize)
    oBitmap = new Bitmap(1,1,PixelFormat.Format32bppARGB)
    g = Graphics.FromImage(oBitmap)
    oStringSize = g.MeasureString(sPhrase, oFontCounter)
    iWidth = cint(oStringSize.Width)
    iHeight = cint(oStringSize.Height)
    g.Dispose()
    oBitmap.Dispose()
   
    ' Create a new image with background color, draw the phrase using font, fontcolor and font size
    oBitmapOut = new Bitmap(iWidth,iHeight,PixelFormat.Format32bppARGB)
    g = Graphics.FromImage(oBitmapOut)
    g.FillRectangle(new SolidBrush(oColorBackground), new Rectangle(0,0,iWidth,iHeight))
    g.DrawString(sPhrase, oFontCounter, new SolidBrush(oFont), 0, 0)
   
    ' Output the image as a PNG into a stream
    oStream = new MemoryStream()
    oBitmapOut.Save(oStream,ImageFormat.PNG)
    ' could be BMP, EMF, GIF, JPEG, PNG, TIFF, WMF
   
    ' Send stream to client
    Response.ClearContent()
    Response.ContentType = "image/PNG"
    Response.BinaryWrite(oStream.ToArray())
    Response.End
   
    ' Clean up
    oFontCounter.Dispose()
    oBitmapOut.Dispose()
    g.Dispose()
    'oStream.Dispose() ' Cant dispose of this -- get an error
    'oStringSize.Dispose() ' Cant dispose of this -- get an error
    'oFont.Dispose()
   
    %>

Thanks, Martin.




Replies:
Posted By: MorningZ
Date Posted: 09 May 2003 at 11:31pm

i do drop shadows a sneaky way....

i draw black text offset i pixel in each direction and then put the colored text over the offsets.. resulting in something like this:

if you want the code for it, just lemme know and i'll post it



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Mart
Date Posted: 10 May 2003 at 2:59pm

Yes could you post the code because I am not sure how to do that...

Thanks, Martin.



Posted By: MorningZ
Date Posted: 11 May 2003 at 8:13am

Cheers

http://www.morningz.com/mz/crystal/dotnet/uploadTIImage.aspx - http://www.morningz.com/mz/crystal/dotnet/uploadTIImage.aspx



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Mart
Date Posted: 11 May 2003 at 9:27am
Could you strip out the upload and resize bit for me because all I need is text and I can't figure out which bit is which thanks Martin.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net