This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
atremblay  
#1 Posted : Saturday, July 25, 2009 5:51:39 PM(UTC)
atremblay

Rank: Newbie

Groups: Guest
Joined: 7/24/2009(UTC)
Posts: 1

I am currently evaluating this product and want to implement curved text. I found an example in the forum, but it does not work exactly as I want. See my example image:

[Image was removed]

First of all the text does not appear as if it is at the correct angle. Secondly, I would like the text to appear centered on the circle like this example:

[Image was removed]

Does anyone have any ideas? Thanks in advance, Al Tremblay

Here is my sample code:

Code:

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Const centerX As Integer = 228
        Const centerY As Integer = 228
        Const radius As Integer = 220

        'Create Bitmap object
        Dim bitmap As New Aurigma.GraphicsMill.Bitmap(450, 450, _
            Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

        Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = _
            bitmap.GetGdiGraphics()

        'Fill background
        graphics.FillRectangle(New Aurigma.GraphicsMill.Drawing.SolidBrush( _
            Aurigma.GraphicsMill.RgbColor.White), 0, 0, 460, 460)

        ' Adjust font settings
        Dim font As New Aurigma.GraphicsMill.Drawing.Font( _
            "verdana", 30, False, False)

        font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Top
        'font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center

        Dim text As String = "THE FIRST ENGLISH SETTLEMENT IN CONNECTICUT"

        'Get characters positions
        Dim positions As Single() = font.GetCharacterPositions(text, 0)

        'Draw ellipse
        graphics.DrawEllipse(New Aurigma.GraphicsMill.Drawing.Pen( _
            Aurigma.GraphicsMill.RgbColor.Black, 1), 0, 0, 450, 450)

        Dim brush As New Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black)

        'Draw character by character
        For i As Integer = 0 To text.Length - 1
            'Compute angle in radians
            Dim angle As Single = positions(i) / radius + Math.PI

            Dim x As Single = centerX + radius * Math.Cos(angle)
            Dim y As Single = centerY + radius * Math.Sin(angle)

            Dim rotateMatrix As New System.Drawing.Drawing2D.Matrix
            rotateMatrix.RotateAt(angle / Math.PI * 180 + 90, _
                New System.Drawing.PointF(x, y)) ''Convert angle from radians to degrees

            graphics.Transform = rotateMatrix

            graphics.DrawString(text.Chars(i), font, brush, x, y)
        Next

        Dim strOutputFilePath As String = Server.MapPath("images\") & "text1.png"
        Dim strNewImagePath As String = "~/images/text1.png"

        bitmap.Save(strOutputFilePath)
        image1.ImageUrl = strNewImagePath

    End Sub

Edited by user Sunday, December 20, 2009 4:27:14 AM(UTC)  | Reason: Not specified

Alex Kon  
#2 Posted : Tuesday, July 28, 2009 9:19:12 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Guest
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello Al,

Take a look at the code sample below. It produces more 'smooth' text and centers text at the top of the circle:

Code:
Private Sub RunTest()
		Dim text As String = "THE FIRST ENGLISH SETTLEMENT IN CONNECTICUT"

		Const centerX As Integer = 300
		Const centerY As Integer = 300
		Const radius As Integer = 200

		'Create Bitmap object
		Dim bitmap As New Aurigma.GraphicsMill.Bitmap( _
		   2 * centerX, _
		   2 * centerY, _
		   Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

		'Fill background
		Dim g As Aurigma.GraphicsMill.Drawing.GdiGraphics = bitmap.GetGdiGraphics()
		g.FillRectangle( _
		   New Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.White), _
		   0, _
		   0, _
		   bitmap.Width, _
		   bitmap.Height)

		'Adjust font settings
        Dim font As new Aurigma.GraphicsMill.Drawing.Font("Tahoma", 37, false, false)
		font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Baseline
		font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center

		'Get characters positions & text dimensions
		Dim positions As Single() = font.GetCharacterPositions(text, 0)
		Dim textSize As SizeF = font.MeasureString(text)

		'Draw ellipse
		g.DrawEllipse( _
		   New Aurigma.GraphicsMill.Drawing.Pen(Aurigma.GraphicsMill.RgbColor.Black, 1), _
		   centerX - radius, _
		   centerY - radius, _
		   radius * 2, _
		   radius * 2)
		Dim brush As New Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black)

		'Calculating basic params
		Dim textAngle As Double = textSize.Width / radius
		Dim startAngle As Double = Math.PI - (Math.PI - textAngle) / 2

		'Draw character by character
		For i As Integer = 0 To text.Length - 1

			Dim charWidth As Single
			If (i < text.Length - 1) Then
				charWidth = positions(i + 1) - positions(i)
			Else
				charWidth = textSize.Width - positions(i) - 1
			End If

			'Compute angle to which rotate current character. Rotation will be
			'performed relative to the middle of the bottom side of the character.
			Dim angle As Double = startAngle - _
			  (positions(i) + charWidth / 2.0F) * textAngle / textSize.Width

			'Compute the x and y coordinate of the bottom/top* middle* of the character
			Dim x As Single = CType(centerX + radius * Math.Cos(angle), Single)
			Dim y As Single = CType(centerY - radius * Math.Sin(angle), Single)

			'Convert angle from radians to degrees
			dim degAngle As Single = CType(90 - angle / Math.PI * 180.0, Single)

			Dim rotateMatrix As New System.Drawing.Drawing2D.Matrix()
			rotateMatrix.RotateAt(degAngle, New System.Drawing.PointF(x, y))

			g.Transform = rotateMatrix
			g.DrawString(text(i).ToString(), font, brush, x, y)
		Next

		bitmap.Save("c:\\temp\\roundTextTmp.bmp")
	End Sub

Here is output of this sample:

Alex Kon attached the following image(s):
roundTextTmp.png
Users browsing this topic
Similar Topics
Write Curved text on an existing image around the round edge (Discussions – Graphics Mill)
by SteveH 12/8/2010 10:14:22 PM(UTC)
Curved text (Discussions – Graphics Mill)
by emg 4/10/2007 5:53:46 AM(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.