Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing a string that follows a path using GDI+

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

like image 972
Mr Jones Avatar asked Aug 02 '12 20:08

Mr Jones


2 Answers

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

like image 152
Luke Baughan Avatar answered Oct 24 '22 08:10

Luke Baughan


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.

like image 41
Mr Jones Avatar answered Oct 24 '22 07:10

Mr Jones