Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2006, 08:01 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default Print a string along a Path

GDI questions are the types of questions that normally stand as Zero Post threads but I am going to go ahead and ask this question anyway.

Using the DrawString() method it is easy enough to draw X string to an image as long as you want it drawn inside a rectangle. How would I go about drawing text along an arch though. (Think Microsof Word Art)

Is this something that I am going to have draw each character and rotate it slightly to give the appearance that it is following an arch or is there someway that I can define an array of coords that it should follow?

"The one language all programmers understand is profanity."
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old July 12th, 2006, 12:24 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

SOLUTION:

I adapted my code from Justin Rogers blog entry: http://weblogs.asp.net/justin_rogers...20/217716.aspx

Using Justin's Circular Textual Layout as a base I began my own coding. You see, following his code your text will follow a path around a circle with each character being rotated to the corrospodning angle that character sits on.

I needed each character to follow that path but be displayed vertically and only encompass half of the circle. (So essitnally if my text started at 180º it would be printed left to right and when it came to 0º I wanted the text to stop) How I figured that out is beyond the scope of this post but below find the source code that will allow you to print text along circular path.

        Dim strString As String = "Wildcats"
        Dim c() As Char = strString.ToCharArray
        Dim radians As Decimal
        Dim xoffset, yoffset, yoffset1 As Decimal
        Dim cx, cy As Integer
        Dim cr As Integer
        Dim cc As Decimal
        Dim carCD As Decimal
        Dim Tsangle As Decimal = 180 'This is the start point

        cx = 122 / 2 'Width of circle
        cy = 122 / 2 'Height of circle

        cr = Convert.ToInt32(cx * 0.9F)
        cc = Convert.ToDecimal(PI * 2 * cr)
        carCD = 0.397
'In his original example, the above code was written as carCD = cc / 360.0F which, essentially, defines how much space is between your printed text. The lower the number the more space that will be between your characters and vice versa

        Dim strImageOut As String = Server.MapPath("./test1.jpg")
        Dim imgJpeg As Bitmap = New Bitmap(130, 130)
        Dim gGraphics As Graphics = Graphics.FromImage(imgJpeg) 'Set the copy to be drawn on
        Dim solidBrushBlk As New SolidBrush(ColorTranslator.FromHtml("#000000")) 'standard black brush
        Dim objFont As New Font(System.Drawing.FontFamily.GenericSansSerif, 12, FontStyle.Regular, GraphicsUnit.Pixel)

          For i = 0 To c.GetUpperBound(0)
            radians = (Tsangle / 180 * PI)
            xoffset = Cos(radians) * cr
            yoffset = Sin(radians) * cr * -1 'by inverting the sine this will send the text along the upper ridge of the circle left to right
            yoffset1 = Sin(radians) * cr 'by not inverting the sine this will send the text along the lower ridge of the circle left to right

            gGraphics.TranslateTransform(cx + xoffset, cy + yoffset)
            gGraphics.DrawString(c(i).ToString, objFont, Brushes.Red, 0, 0)
            gGraphics.ResetTransform()

            gGraphics.TranslateTransform(cx + xoffset, cy + yoffset1)
            gGraphics.DrawString(c(i).ToString, objFont, Brushes.White, 0, 0)
            gGraphics.ResetTransform()
            Tsangle -= (objSize.Width / carCD)
        Next

        Dim encoderParams As System.Drawing.Imaging.EncoderParameters = New System.Drawing.Imaging.EncoderParameters
        Dim encoderParam As System.Drawing.Imaging.EncoderParameter = New System.Drawing.Imaging.EncoderParameter(System.Dra wing.Imaging.Encoder.Quality, 100)
        encoderParams.Param(0) = encoderParam

        Dim arrayICI As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
        Dim jpegICI As ImageCodecInfo

        For x = 0 To arrayICI.Length - 1
            If (arrayICI(x).FormatDescription.Equals("JPEG")) Then
                jpegICI = arrayICI(x)
                Exit For
            End If
        Next

        If Not jpegICI Is Nothing Then
            imgJpeg.Save(strImageOut, jpegICI, encoderParams)
        End If

        gGraphics.Dispose()
        imgJpeg.Dispose()

The above code will print a black square and to strings of text, one red and one white. The red string will follow the upper ridge of the circle and the white string will follow the lower ridge of the cricle both moving left to right.

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with path for loading Pics (app.path) Tabbasum Beginning VB 6 2 November 15th, 2007 04:57 AM
string to x-path - EXSLT - dynamic functions Geierwally XSLT 1 July 12th, 2007 10:35 AM
Need to print a string value in a single line simmy_tj BOOK: Beginning Java 2 1 February 13th, 2007 06:36 AM
Variable Path in web.Config Connection String? ElPato General .NET 4 June 21st, 2004 05:44 PM
Relative Path Connection String fangai Classic ASP Databases 1 October 3rd, 2003 02:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.