locked
Dynamic Text Replacement RRS feed

  • Question

  • User-782260167 posted
    I need to take standard text and use a true type font to generate an image (.jpg, .gif, .png, etc) based on that text, leveraging the .NET GDI+ library. Microsoft uses this technique on their site and I was hoping someone has or knows someone with this type of class along with a demonstration. Flash experts have been able to do this embeding a flash object in their CSS and using standard HTML tags to call the Flash object. ESPN & ABCNEWS use dynamic text replacement inplace of simple graphic titles. Examples of Vendors or Open Source Font Velocity www.fontvelocity.com Demo http://www.fontvelocity.com/products/fvsamplenew.asp This is another great example but I would like to see this done using the .NET GDI+ Article http://www.alistapart.com/articles/dynatext/ Demo http://www.stewartspeak.com/dtr/demo/
    Thursday, October 28, 2004 5:53 PM

All replies

  • User217889999 posted
    Here you are, courtesy of Stephen Walther, author of Asp.Net Unleashed: <%@ Page ContentType="image/jpeg" %> <%@ Import namespace="System.Drawing" %> <%@ Import namespace="System.Drawing.Imaging" %> <%@ Import namespace="System.Drawing.Text" %> <script Runat="Server"> Sub Page_Load Dim objBitmap As Bitmap Dim objGraphics As Graphics Dim strString As String ' Create Bitmap objBitmap = New Bitmap( 600, 400 ) ' Create Graphics objGraphics = Graphics.FromImage( objBitmap ) objGraphics.Clear( Color.DarkBlue ) ' Prepare Font Dim objFont As New Font( "Times", 24 ) strString = "ABCabc123 - AntiAlias" objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias objGraphics.DrawString( strString, objFont, Brushes.White, 10, 10 ) strString = "ABCabc123 - AntiAliasGridFit" objGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit objGraphics.DrawString( strString, objFont, Brushes.White, 10, 50 ) strString = "ABCabc123 - ClearTypeGridFit" objGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit objGraphics.DrawString( strString, objFont, Brushes.White, 10, 90 ) strString = "ABCabc123 - SingleBitPerPixel" objGraphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel objGraphics.DrawString( strString, objFont, Brushes.White, 10, 130 ) strString = "ABCabc123 - SingleBitPerPixelGridFit" objGraphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel objGraphics.DrawString( strString, objFont, Brushes.White, 10, 170 ) strString = "ABCabc123 - SystemDefault" objGraphics.TextRenderingHint = TextRenderingHint.SystemDefault objGraphics.DrawString( strString, objFont, Brushes.White, 10, 210 ) ' Display Bitmap objBitmap.Save( Response.OutputStream, ImageFormat.JPEG ) End Sub </script> Simply paste the above into an .aspx page and view (must be in a web/virtual folder of course)
    Wednesday, November 3, 2004 7:28 AM