8

I've been scratching my head over this all day. I need to dynamically create an image that contains a string provided by the client. The only problem is, the string needs to be drawn along a curve like the image below. I would also like to specify the angle of the curve because this text needs to be displayed on a number of products, and the curve varies on each product.

I've attempted to loop through the string and display each character and give each one a specific coordinate to resemble a parabola, but in order for that to be useful, each character needs to be rotated to fit the curve. Does anyone have any suggestions from the System.Drawing library that may be of use to me?

enter image description here

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Mr Jones
  • 1,188
  • 3
  • 17
  • 33
  • 7
    This guy has an extensive blog post on the subject (and how to do it in C#): http://www.planetclegg.com/projects/WarpingTextToSplines.html – Michael Graczyk Aug 02 '12 at 20:29
  • Try this: http://stackoverflow.com/a/11151457/622391 – Simon MᶜKenzie Aug 03 '12 at 00:05
  • possible duplicate of [How to create curved Text on a Bitmap?](http://stackoverflow.com/questions/2803853/how-to-create-curved-text-on-a-bitmap) – Jeremy Aug 03 '12 at 01:56
  • 1
    @MichaelGraczyk I was able to generate some curved text. I had to replace `textPath.PathPoints[i] = new PointF(finalX, finalY);` with `newPoints[i] = new PointF(finalX, finalY); newPath = new GraphicsPath(newPoints, textPath.PathTypes);` because PathPoints is a read-only array. Less efficient than I would like due to creating a new path each iteration. Also, It's squished and stretched so it'll take a bit of playing around to get it looking right, but nevertheless, the text is following a curved path. – Mr Jones Aug 03 '12 at 13:36

2 Answers2

1

I found this article on Code Project related to drawing text along a path in VB.NET - I'm sure a standard code converter could change this automatically to C# for you and it may solve your problem!

http://www.codeproject.com/Articles/13864/Text-on-Path-with-VB-NET

Luke Baughan
  • 4,658
  • 3
  • 31
  • 54
1

After doing a bit of research, it seems that WPF is the best route to take when generating warped text. A few google searches led me to this project. There is a minimal amount of XAML, and it's still written in C#. Credit goes to @lneir on codeproject for providing this remarkable bit of code. It's scalable, flexible, and wonderfully written, and the best part... no bezier curves.

I also mentioned that this text needs to be rendered on a dynamically created image. Turns out you can convert any WPF control to an image. Here's a link I found.

Thanks for the responses.

Mr Jones
  • 1,188
  • 3
  • 17
  • 33