How can I render curved text into a Bitmap?
up vote
4
down vote
favorite
I am currently dynamically creating a bitmap and using the graphics object from the bitmap to draw a string on it like so:
System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp);
graph.DrawString(text, font, brush, new System.Drawing.Point(0, 0));
This returns a rectangular bitmap with the string written straight across from left to right.
I would like to also be able to draw the string in the shape of a rainbow.
How can I do this?
c# bitmap gdi+ text-rendering
add a comment |
up vote
4
down vote
favorite
I am currently dynamically creating a bitmap and using the graphics object from the bitmap to draw a string on it like so:
System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp);
graph.DrawString(text, font, brush, new System.Drawing.Point(0, 0));
This returns a rectangular bitmap with the string written straight across from left to right.
I would like to also be able to draw the string in the shape of a rainbow.
How can I do this?
c# bitmap gdi+ text-rendering
1
Were any of these answers helpful? I just came across this question and might code something similar soon, but none of the answers have been accepted - I am wondering if there were problems with them, and what you ended up doing.
– David M
May 13 '13 at 11:48
Use this: csharphelper.com/blog/2016/01/draw-text-on-a-curve-in-c
– M.R.T2017
Aug 18 at 14:15
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I am currently dynamically creating a bitmap and using the graphics object from the bitmap to draw a string on it like so:
System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp);
graph.DrawString(text, font, brush, new System.Drawing.Point(0, 0));
This returns a rectangular bitmap with the string written straight across from left to right.
I would like to also be able to draw the string in the shape of a rainbow.
How can I do this?
c# bitmap gdi+ text-rendering
I am currently dynamically creating a bitmap and using the graphics object from the bitmap to draw a string on it like so:
System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp);
graph.DrawString(text, font, brush, new System.Drawing.Point(0, 0));
This returns a rectangular bitmap with the string written straight across from left to right.
I would like to also be able to draw the string in the shape of a rainbow.
How can I do this?
c# bitmap gdi+ text-rendering
c# bitmap gdi+ text-rendering
edited Aug 28 '14 at 3:48
Simon MᶜKenzie
6,205133257
6,205133257
asked May 10 '10 at 15:22
etoisarobot
4,279114372
4,279114372
1
Were any of these answers helpful? I just came across this question and might code something similar soon, but none of the answers have been accepted - I am wondering if there were problems with them, and what you ended up doing.
– David M
May 13 '13 at 11:48
Use this: csharphelper.com/blog/2016/01/draw-text-on-a-curve-in-c
– M.R.T2017
Aug 18 at 14:15
add a comment |
1
Were any of these answers helpful? I just came across this question and might code something similar soon, but none of the answers have been accepted - I am wondering if there were problems with them, and what you ended up doing.
– David M
May 13 '13 at 11:48
Use this: csharphelper.com/blog/2016/01/draw-text-on-a-curve-in-c
– M.R.T2017
Aug 18 at 14:15
1
1
Were any of these answers helpful? I just came across this question and might code something similar soon, but none of the answers have been accepted - I am wondering if there were problems with them, and what you ended up doing.
– David M
May 13 '13 at 11:48
Were any of these answers helpful? I just came across this question and might code something similar soon, but none of the answers have been accepted - I am wondering if there were problems with them, and what you ended up doing.
– David M
May 13 '13 at 11:48
Use this: csharphelper.com/blog/2016/01/draw-text-on-a-curve-in-c
– M.R.T2017
Aug 18 at 14:15
Use this: csharphelper.com/blog/2016/01/draw-text-on-a-curve-in-c
– M.R.T2017
Aug 18 at 14:15
add a comment |
3 Answers
3
active
oldest
votes
up vote
17
down vote
I recently had this problem (I was rendering text for printing onto CDs), so here's my solution:
private void DrawCurvedText(Graphics graphics, string text, Point centre, float distanceFromCentreToBaseOfText, float radiansToTextCentre, Font font, Brush brush)
{
// Circumference for use later
var circleCircumference = (float)(Math.PI * 2 * distanceFromCentreToBaseOfText);
// Get the width of each character
var characterWidths = GetCharacterWidths(graphics, text, font).ToArray();
// The overall height of the string
var characterHeight = graphics.MeasureString(text, font).Height;
var textLength = characterWidths.Sum();
// The string length above is the arc length we'll use for rendering the string. Work out the starting angle required to
// centre the text across the radiansToTextCentre.
float fractionOfCircumference = textLength / circleCircumference;
float currentCharacterRadians = radiansToTextCentre + (float)(Math.PI * fractionOfCircumference);
for (int characterIndex = 0; characterIndex < text.Length; characterIndex++)
{
char @char = text[characterIndex];
// Polar to cartesian
float x = (float)(distanceFromCentreToBaseOfText * Math.Sin(currentCharacterRadians));
float y = -(float)(distanceFromCentreToBaseOfText * Math.Cos(currentCharacterRadians));
using (GraphicsPath characterPath = new GraphicsPath())
{
characterPath.AddString(@char.ToString(), font.FontFamily, (int)font.Style, font.Size, Point.Empty,
StringFormat.GenericTypographic);
var pathBounds = characterPath.GetBounds();
// Transformation matrix to move the character to the correct location.
// Note that all actions on the Matrix class are prepended, so we apply them in reverse.
var transform = new Matrix();
// Translate to the final position
transform.Translate(centre.X + x, centre.Y + y);
// Rotate the character
var rotationAngleDegrees = currentCharacterRadians * 180F / (float)Math.PI - 180F;
transform.Rotate(rotationAngleDegrees);
// Translate the character so the centre of its base is over the origin
transform.Translate(-pathBounds.Width / 2F, -characterHeight);
characterPath.Transform(transform);
// Draw the character
graphics.FillPath(brush, characterPath);
}
if (characterIndex != text.Length - 1)
{
// Move "currentCharacterRadians" on to the next character
var distanceToNextChar = (characterWidths[characterIndex] + characterWidths[characterIndex + 1]) / 2F;
float charFractionOfCircumference = distanceToNextChar / circleCircumference;
currentCharacterRadians -= charFractionOfCircumference * (float)(2F * Math.PI);
}
}
}
private IEnumerable<float> GetCharacterWidths(Graphics graphics, string text, Font font)
{
// The length of a space. Necessary because a space measured using StringFormat.GenericTypographic has no width.
// We can't use StringFormat.GenericDefault for the characters themselves, as it adds unwanted spacing.
var spaceLength = graphics.MeasureString(" ", font, Point.Empty, StringFormat.GenericDefault).Width;
return text.Select(c => c == ' ' ? spaceLength : graphics.MeasureString(c.ToString(), font, Point.Empty, StringFormat.GenericTypographic).Width);
}
1
Of all of the countless posts on the internet, this is the only example I've found of a fairly simple method of doing this. I was in the process of using bezier curves to achieve it. Thanks @Simon.
– Echilon
Sep 10 '13 at 16:06
One slight observation with this is that text goes anti-clockwise. Is it possible to make it go clockwise instead?
– Echilon
Sep 10 '13 at 16:15
3
Hi @Echilon, you can reverse the curve by changing a couple of lines: remove the-180F
when calculatingrotationAngleDegrees
, and in the 2 places wherecurrentCharacterRadians
is assigned, change the subtractions to additions and vice versa!
– Simon MᶜKenzie
Sep 11 '13 at 4:45
Works great. Thanks.
– Echilon
Sep 11 '13 at 18:23
1
@Rasool, I'm afraid that's beyond my expertise! You should ask a new question about it, explaining the rtl problem. Good luck!
– Simon MᶜKenzie
Mar 20 '15 at 8:43
|
show 4 more comments
up vote
1
down vote
I think the only way is to render each character individually and use the
Graphics.RotateTransform
to rotate the text. You'll need to work out the rotation angle and rendering offset yourself. You can use the
Graphics.MeasureCharacterRanges
to get the size of each character.
I personally am going to love this solution! +1 :) Thanks for suggestion.
– Afzaal Ahmad Zeeshan
Aug 17 '14 at 12:27
add a comment |
up vote
0
down vote
Unfortunatelly in GDI+ there is no way to attach Strings to a path (this is what you would be looking for).
So the only way to do this is doing it "by hand". That means splitting up the string into characters and placing them based on your own path calculations.
Unless you want to put a lot of work into this you should try to find a library (potentially complete GDI+ replacement) to do this or give up on your rainbow.
With WPF you can render text on a path (see link for a howto)
8 years, and still working. Thanks for this
– HEWhoDoesn'tKnow
Nov 10 at 0:55
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
17
down vote
I recently had this problem (I was rendering text for printing onto CDs), so here's my solution:
private void DrawCurvedText(Graphics graphics, string text, Point centre, float distanceFromCentreToBaseOfText, float radiansToTextCentre, Font font, Brush brush)
{
// Circumference for use later
var circleCircumference = (float)(Math.PI * 2 * distanceFromCentreToBaseOfText);
// Get the width of each character
var characterWidths = GetCharacterWidths(graphics, text, font).ToArray();
// The overall height of the string
var characterHeight = graphics.MeasureString(text, font).Height;
var textLength = characterWidths.Sum();
// The string length above is the arc length we'll use for rendering the string. Work out the starting angle required to
// centre the text across the radiansToTextCentre.
float fractionOfCircumference = textLength / circleCircumference;
float currentCharacterRadians = radiansToTextCentre + (float)(Math.PI * fractionOfCircumference);
for (int characterIndex = 0; characterIndex < text.Length; characterIndex++)
{
char @char = text[characterIndex];
// Polar to cartesian
float x = (float)(distanceFromCentreToBaseOfText * Math.Sin(currentCharacterRadians));
float y = -(float)(distanceFromCentreToBaseOfText * Math.Cos(currentCharacterRadians));
using (GraphicsPath characterPath = new GraphicsPath())
{
characterPath.AddString(@char.ToString(), font.FontFamily, (int)font.Style, font.Size, Point.Empty,
StringFormat.GenericTypographic);
var pathBounds = characterPath.GetBounds();
// Transformation matrix to move the character to the correct location.
// Note that all actions on the Matrix class are prepended, so we apply them in reverse.
var transform = new Matrix();
// Translate to the final position
transform.Translate(centre.X + x, centre.Y + y);
// Rotate the character
var rotationAngleDegrees = currentCharacterRadians * 180F / (float)Math.PI - 180F;
transform.Rotate(rotationAngleDegrees);
// Translate the character so the centre of its base is over the origin
transform.Translate(-pathBounds.Width / 2F, -characterHeight);
characterPath.Transform(transform);
// Draw the character
graphics.FillPath(brush, characterPath);
}
if (characterIndex != text.Length - 1)
{
// Move "currentCharacterRadians" on to the next character
var distanceToNextChar = (characterWidths[characterIndex] + characterWidths[characterIndex + 1]) / 2F;
float charFractionOfCircumference = distanceToNextChar / circleCircumference;
currentCharacterRadians -= charFractionOfCircumference * (float)(2F * Math.PI);
}
}
}
private IEnumerable<float> GetCharacterWidths(Graphics graphics, string text, Font font)
{
// The length of a space. Necessary because a space measured using StringFormat.GenericTypographic has no width.
// We can't use StringFormat.GenericDefault for the characters themselves, as it adds unwanted spacing.
var spaceLength = graphics.MeasureString(" ", font, Point.Empty, StringFormat.GenericDefault).Width;
return text.Select(c => c == ' ' ? spaceLength : graphics.MeasureString(c.ToString(), font, Point.Empty, StringFormat.GenericTypographic).Width);
}
1
Of all of the countless posts on the internet, this is the only example I've found of a fairly simple method of doing this. I was in the process of using bezier curves to achieve it. Thanks @Simon.
– Echilon
Sep 10 '13 at 16:06
One slight observation with this is that text goes anti-clockwise. Is it possible to make it go clockwise instead?
– Echilon
Sep 10 '13 at 16:15
3
Hi @Echilon, you can reverse the curve by changing a couple of lines: remove the-180F
when calculatingrotationAngleDegrees
, and in the 2 places wherecurrentCharacterRadians
is assigned, change the subtractions to additions and vice versa!
– Simon MᶜKenzie
Sep 11 '13 at 4:45
Works great. Thanks.
– Echilon
Sep 11 '13 at 18:23
1
@Rasool, I'm afraid that's beyond my expertise! You should ask a new question about it, explaining the rtl problem. Good luck!
– Simon MᶜKenzie
Mar 20 '15 at 8:43
|
show 4 more comments
up vote
17
down vote
I recently had this problem (I was rendering text for printing onto CDs), so here's my solution:
private void DrawCurvedText(Graphics graphics, string text, Point centre, float distanceFromCentreToBaseOfText, float radiansToTextCentre, Font font, Brush brush)
{
// Circumference for use later
var circleCircumference = (float)(Math.PI * 2 * distanceFromCentreToBaseOfText);
// Get the width of each character
var characterWidths = GetCharacterWidths(graphics, text, font).ToArray();
// The overall height of the string
var characterHeight = graphics.MeasureString(text, font).Height;
var textLength = characterWidths.Sum();
// The string length above is the arc length we'll use for rendering the string. Work out the starting angle required to
// centre the text across the radiansToTextCentre.
float fractionOfCircumference = textLength / circleCircumference;
float currentCharacterRadians = radiansToTextCentre + (float)(Math.PI * fractionOfCircumference);
for (int characterIndex = 0; characterIndex < text.Length; characterIndex++)
{
char @char = text[characterIndex];
// Polar to cartesian
float x = (float)(distanceFromCentreToBaseOfText * Math.Sin(currentCharacterRadians));
float y = -(float)(distanceFromCentreToBaseOfText * Math.Cos(currentCharacterRadians));
using (GraphicsPath characterPath = new GraphicsPath())
{
characterPath.AddString(@char.ToString(), font.FontFamily, (int)font.Style, font.Size, Point.Empty,
StringFormat.GenericTypographic);
var pathBounds = characterPath.GetBounds();
// Transformation matrix to move the character to the correct location.
// Note that all actions on the Matrix class are prepended, so we apply them in reverse.
var transform = new Matrix();
// Translate to the final position
transform.Translate(centre.X + x, centre.Y + y);
// Rotate the character
var rotationAngleDegrees = currentCharacterRadians * 180F / (float)Math.PI - 180F;
transform.Rotate(rotationAngleDegrees);
// Translate the character so the centre of its base is over the origin
transform.Translate(-pathBounds.Width / 2F, -characterHeight);
characterPath.Transform(transform);
// Draw the character
graphics.FillPath(brush, characterPath);
}
if (characterIndex != text.Length - 1)
{
// Move "currentCharacterRadians" on to the next character
var distanceToNextChar = (characterWidths[characterIndex] + characterWidths[characterIndex + 1]) / 2F;
float charFractionOfCircumference = distanceToNextChar / circleCircumference;
currentCharacterRadians -= charFractionOfCircumference * (float)(2F * Math.PI);
}
}
}
private IEnumerable<float> GetCharacterWidths(Graphics graphics, string text, Font font)
{
// The length of a space. Necessary because a space measured using StringFormat.GenericTypographic has no width.
// We can't use StringFormat.GenericDefault for the characters themselves, as it adds unwanted spacing.
var spaceLength = graphics.MeasureString(" ", font, Point.Empty, StringFormat.GenericDefault).Width;
return text.Select(c => c == ' ' ? spaceLength : graphics.MeasureString(c.ToString(), font, Point.Empty, StringFormat.GenericTypographic).Width);
}
1
Of all of the countless posts on the internet, this is the only example I've found of a fairly simple method of doing this. I was in the process of using bezier curves to achieve it. Thanks @Simon.
– Echilon
Sep 10 '13 at 16:06
One slight observation with this is that text goes anti-clockwise. Is it possible to make it go clockwise instead?
– Echilon
Sep 10 '13 at 16:15
3
Hi @Echilon, you can reverse the curve by changing a couple of lines: remove the-180F
when calculatingrotationAngleDegrees
, and in the 2 places wherecurrentCharacterRadians
is assigned, change the subtractions to additions and vice versa!
– Simon MᶜKenzie
Sep 11 '13 at 4:45
Works great. Thanks.
– Echilon
Sep 11 '13 at 18:23
1
@Rasool, I'm afraid that's beyond my expertise! You should ask a new question about it, explaining the rtl problem. Good luck!
– Simon MᶜKenzie
Mar 20 '15 at 8:43
|
show 4 more comments
up vote
17
down vote
up vote
17
down vote
I recently had this problem (I was rendering text for printing onto CDs), so here's my solution:
private void DrawCurvedText(Graphics graphics, string text, Point centre, float distanceFromCentreToBaseOfText, float radiansToTextCentre, Font font, Brush brush)
{
// Circumference for use later
var circleCircumference = (float)(Math.PI * 2 * distanceFromCentreToBaseOfText);
// Get the width of each character
var characterWidths = GetCharacterWidths(graphics, text, font).ToArray();
// The overall height of the string
var characterHeight = graphics.MeasureString(text, font).Height;
var textLength = characterWidths.Sum();
// The string length above is the arc length we'll use for rendering the string. Work out the starting angle required to
// centre the text across the radiansToTextCentre.
float fractionOfCircumference = textLength / circleCircumference;
float currentCharacterRadians = radiansToTextCentre + (float)(Math.PI * fractionOfCircumference);
for (int characterIndex = 0; characterIndex < text.Length; characterIndex++)
{
char @char = text[characterIndex];
// Polar to cartesian
float x = (float)(distanceFromCentreToBaseOfText * Math.Sin(currentCharacterRadians));
float y = -(float)(distanceFromCentreToBaseOfText * Math.Cos(currentCharacterRadians));
using (GraphicsPath characterPath = new GraphicsPath())
{
characterPath.AddString(@char.ToString(), font.FontFamily, (int)font.Style, font.Size, Point.Empty,
StringFormat.GenericTypographic);
var pathBounds = characterPath.GetBounds();
// Transformation matrix to move the character to the correct location.
// Note that all actions on the Matrix class are prepended, so we apply them in reverse.
var transform = new Matrix();
// Translate to the final position
transform.Translate(centre.X + x, centre.Y + y);
// Rotate the character
var rotationAngleDegrees = currentCharacterRadians * 180F / (float)Math.PI - 180F;
transform.Rotate(rotationAngleDegrees);
// Translate the character so the centre of its base is over the origin
transform.Translate(-pathBounds.Width / 2F, -characterHeight);
characterPath.Transform(transform);
// Draw the character
graphics.FillPath(brush, characterPath);
}
if (characterIndex != text.Length - 1)
{
// Move "currentCharacterRadians" on to the next character
var distanceToNextChar = (characterWidths[characterIndex] + characterWidths[characterIndex + 1]) / 2F;
float charFractionOfCircumference = distanceToNextChar / circleCircumference;
currentCharacterRadians -= charFractionOfCircumference * (float)(2F * Math.PI);
}
}
}
private IEnumerable<float> GetCharacterWidths(Graphics graphics, string text, Font font)
{
// The length of a space. Necessary because a space measured using StringFormat.GenericTypographic has no width.
// We can't use StringFormat.GenericDefault for the characters themselves, as it adds unwanted spacing.
var spaceLength = graphics.MeasureString(" ", font, Point.Empty, StringFormat.GenericDefault).Width;
return text.Select(c => c == ' ' ? spaceLength : graphics.MeasureString(c.ToString(), font, Point.Empty, StringFormat.GenericTypographic).Width);
}
I recently had this problem (I was rendering text for printing onto CDs), so here's my solution:
private void DrawCurvedText(Graphics graphics, string text, Point centre, float distanceFromCentreToBaseOfText, float radiansToTextCentre, Font font, Brush brush)
{
// Circumference for use later
var circleCircumference = (float)(Math.PI * 2 * distanceFromCentreToBaseOfText);
// Get the width of each character
var characterWidths = GetCharacterWidths(graphics, text, font).ToArray();
// The overall height of the string
var characterHeight = graphics.MeasureString(text, font).Height;
var textLength = characterWidths.Sum();
// The string length above is the arc length we'll use for rendering the string. Work out the starting angle required to
// centre the text across the radiansToTextCentre.
float fractionOfCircumference = textLength / circleCircumference;
float currentCharacterRadians = radiansToTextCentre + (float)(Math.PI * fractionOfCircumference);
for (int characterIndex = 0; characterIndex < text.Length; characterIndex++)
{
char @char = text[characterIndex];
// Polar to cartesian
float x = (float)(distanceFromCentreToBaseOfText * Math.Sin(currentCharacterRadians));
float y = -(float)(distanceFromCentreToBaseOfText * Math.Cos(currentCharacterRadians));
using (GraphicsPath characterPath = new GraphicsPath())
{
characterPath.AddString(@char.ToString(), font.FontFamily, (int)font.Style, font.Size, Point.Empty,
StringFormat.GenericTypographic);
var pathBounds = characterPath.GetBounds();
// Transformation matrix to move the character to the correct location.
// Note that all actions on the Matrix class are prepended, so we apply them in reverse.
var transform = new Matrix();
// Translate to the final position
transform.Translate(centre.X + x, centre.Y + y);
// Rotate the character
var rotationAngleDegrees = currentCharacterRadians * 180F / (float)Math.PI - 180F;
transform.Rotate(rotationAngleDegrees);
// Translate the character so the centre of its base is over the origin
transform.Translate(-pathBounds.Width / 2F, -characterHeight);
characterPath.Transform(transform);
// Draw the character
graphics.FillPath(brush, characterPath);
}
if (characterIndex != text.Length - 1)
{
// Move "currentCharacterRadians" on to the next character
var distanceToNextChar = (characterWidths[characterIndex] + characterWidths[characterIndex + 1]) / 2F;
float charFractionOfCircumference = distanceToNextChar / circleCircumference;
currentCharacterRadians -= charFractionOfCircumference * (float)(2F * Math.PI);
}
}
}
private IEnumerable<float> GetCharacterWidths(Graphics graphics, string text, Font font)
{
// The length of a space. Necessary because a space measured using StringFormat.GenericTypographic has no width.
// We can't use StringFormat.GenericDefault for the characters themselves, as it adds unwanted spacing.
var spaceLength = graphics.MeasureString(" ", font, Point.Empty, StringFormat.GenericDefault).Width;
return text.Select(c => c == ' ' ? spaceLength : graphics.MeasureString(c.ToString(), font, Point.Empty, StringFormat.GenericTypographic).Width);
}
answered Jun 22 '12 at 6:53
Simon MᶜKenzie
6,205133257
6,205133257
1
Of all of the countless posts on the internet, this is the only example I've found of a fairly simple method of doing this. I was in the process of using bezier curves to achieve it. Thanks @Simon.
– Echilon
Sep 10 '13 at 16:06
One slight observation with this is that text goes anti-clockwise. Is it possible to make it go clockwise instead?
– Echilon
Sep 10 '13 at 16:15
3
Hi @Echilon, you can reverse the curve by changing a couple of lines: remove the-180F
when calculatingrotationAngleDegrees
, and in the 2 places wherecurrentCharacterRadians
is assigned, change the subtractions to additions and vice versa!
– Simon MᶜKenzie
Sep 11 '13 at 4:45
Works great. Thanks.
– Echilon
Sep 11 '13 at 18:23
1
@Rasool, I'm afraid that's beyond my expertise! You should ask a new question about it, explaining the rtl problem. Good luck!
– Simon MᶜKenzie
Mar 20 '15 at 8:43
|
show 4 more comments
1
Of all of the countless posts on the internet, this is the only example I've found of a fairly simple method of doing this. I was in the process of using bezier curves to achieve it. Thanks @Simon.
– Echilon
Sep 10 '13 at 16:06
One slight observation with this is that text goes anti-clockwise. Is it possible to make it go clockwise instead?
– Echilon
Sep 10 '13 at 16:15
3
Hi @Echilon, you can reverse the curve by changing a couple of lines: remove the-180F
when calculatingrotationAngleDegrees
, and in the 2 places wherecurrentCharacterRadians
is assigned, change the subtractions to additions and vice versa!
– Simon MᶜKenzie
Sep 11 '13 at 4:45
Works great. Thanks.
– Echilon
Sep 11 '13 at 18:23
1
@Rasool, I'm afraid that's beyond my expertise! You should ask a new question about it, explaining the rtl problem. Good luck!
– Simon MᶜKenzie
Mar 20 '15 at 8:43
1
1
Of all of the countless posts on the internet, this is the only example I've found of a fairly simple method of doing this. I was in the process of using bezier curves to achieve it. Thanks @Simon.
– Echilon
Sep 10 '13 at 16:06
Of all of the countless posts on the internet, this is the only example I've found of a fairly simple method of doing this. I was in the process of using bezier curves to achieve it. Thanks @Simon.
– Echilon
Sep 10 '13 at 16:06
One slight observation with this is that text goes anti-clockwise. Is it possible to make it go clockwise instead?
– Echilon
Sep 10 '13 at 16:15
One slight observation with this is that text goes anti-clockwise. Is it possible to make it go clockwise instead?
– Echilon
Sep 10 '13 at 16:15
3
3
Hi @Echilon, you can reverse the curve by changing a couple of lines: remove the
-180F
when calculating rotationAngleDegrees
, and in the 2 places where currentCharacterRadians
is assigned, change the subtractions to additions and vice versa!– Simon MᶜKenzie
Sep 11 '13 at 4:45
Hi @Echilon, you can reverse the curve by changing a couple of lines: remove the
-180F
when calculating rotationAngleDegrees
, and in the 2 places where currentCharacterRadians
is assigned, change the subtractions to additions and vice versa!– Simon MᶜKenzie
Sep 11 '13 at 4:45
Works great. Thanks.
– Echilon
Sep 11 '13 at 18:23
Works great. Thanks.
– Echilon
Sep 11 '13 at 18:23
1
1
@Rasool, I'm afraid that's beyond my expertise! You should ask a new question about it, explaining the rtl problem. Good luck!
– Simon MᶜKenzie
Mar 20 '15 at 8:43
@Rasool, I'm afraid that's beyond my expertise! You should ask a new question about it, explaining the rtl problem. Good luck!
– Simon MᶜKenzie
Mar 20 '15 at 8:43
|
show 4 more comments
up vote
1
down vote
I think the only way is to render each character individually and use the
Graphics.RotateTransform
to rotate the text. You'll need to work out the rotation angle and rendering offset yourself. You can use the
Graphics.MeasureCharacterRanges
to get the size of each character.
I personally am going to love this solution! +1 :) Thanks for suggestion.
– Afzaal Ahmad Zeeshan
Aug 17 '14 at 12:27
add a comment |
up vote
1
down vote
I think the only way is to render each character individually and use the
Graphics.RotateTransform
to rotate the text. You'll need to work out the rotation angle and rendering offset yourself. You can use the
Graphics.MeasureCharacterRanges
to get the size of each character.
I personally am going to love this solution! +1 :) Thanks for suggestion.
– Afzaal Ahmad Zeeshan
Aug 17 '14 at 12:27
add a comment |
up vote
1
down vote
up vote
1
down vote
I think the only way is to render each character individually and use the
Graphics.RotateTransform
to rotate the text. You'll need to work out the rotation angle and rendering offset yourself. You can use the
Graphics.MeasureCharacterRanges
to get the size of each character.
I think the only way is to render each character individually and use the
Graphics.RotateTransform
to rotate the text. You'll need to work out the rotation angle and rendering offset yourself. You can use the
Graphics.MeasureCharacterRanges
to get the size of each character.
answered May 10 '10 at 15:26
Skizz
43.5k859101
43.5k859101
I personally am going to love this solution! +1 :) Thanks for suggestion.
– Afzaal Ahmad Zeeshan
Aug 17 '14 at 12:27
add a comment |
I personally am going to love this solution! +1 :) Thanks for suggestion.
– Afzaal Ahmad Zeeshan
Aug 17 '14 at 12:27
I personally am going to love this solution! +1 :) Thanks for suggestion.
– Afzaal Ahmad Zeeshan
Aug 17 '14 at 12:27
I personally am going to love this solution! +1 :) Thanks for suggestion.
– Afzaal Ahmad Zeeshan
Aug 17 '14 at 12:27
add a comment |
up vote
0
down vote
Unfortunatelly in GDI+ there is no way to attach Strings to a path (this is what you would be looking for).
So the only way to do this is doing it "by hand". That means splitting up the string into characters and placing them based on your own path calculations.
Unless you want to put a lot of work into this you should try to find a library (potentially complete GDI+ replacement) to do this or give up on your rainbow.
With WPF you can render text on a path (see link for a howto)
8 years, and still working. Thanks for this
– HEWhoDoesn'tKnow
Nov 10 at 0:55
add a comment |
up vote
0
down vote
Unfortunatelly in GDI+ there is no way to attach Strings to a path (this is what you would be looking for).
So the only way to do this is doing it "by hand". That means splitting up the string into characters and placing them based on your own path calculations.
Unless you want to put a lot of work into this you should try to find a library (potentially complete GDI+ replacement) to do this or give up on your rainbow.
With WPF you can render text on a path (see link for a howto)
8 years, and still working. Thanks for this
– HEWhoDoesn'tKnow
Nov 10 at 0:55
add a comment |
up vote
0
down vote
up vote
0
down vote
Unfortunatelly in GDI+ there is no way to attach Strings to a path (this is what you would be looking for).
So the only way to do this is doing it "by hand". That means splitting up the string into characters and placing them based on your own path calculations.
Unless you want to put a lot of work into this you should try to find a library (potentially complete GDI+ replacement) to do this or give up on your rainbow.
With WPF you can render text on a path (see link for a howto)
Unfortunatelly in GDI+ there is no way to attach Strings to a path (this is what you would be looking for).
So the only way to do this is doing it "by hand". That means splitting up the string into characters and placing them based on your own path calculations.
Unless you want to put a lot of work into this you should try to find a library (potentially complete GDI+ replacement) to do this or give up on your rainbow.
With WPF you can render text on a path (see link for a howto)
edited May 10 '10 at 15:32
answered May 10 '10 at 15:26
Foxfire
5,2211628
5,2211628
8 years, and still working. Thanks for this
– HEWhoDoesn'tKnow
Nov 10 at 0:55
add a comment |
8 years, and still working. Thanks for this
– HEWhoDoesn'tKnow
Nov 10 at 0:55
8 years, and still working. Thanks for this
– HEWhoDoesn'tKnow
Nov 10 at 0:55
8 years, and still working. Thanks for this
– HEWhoDoesn'tKnow
Nov 10 at 0:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2803853%2fhow-can-i-render-curved-text-into-a-bitmap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Were any of these answers helpful? I just came across this question and might code something similar soon, but none of the answers have been accepted - I am wondering if there were problems with them, and what you ended up doing.
– David M
May 13 '13 at 11:48
Use this: csharphelper.com/blog/2016/01/draw-text-on-a-curve-in-c
– M.R.T2017
Aug 18 at 14:15