|
[Visual Basic]
Dim ca As New Canvas
Dim txt, pars As String
Dim len As Integer
txt = "In a hole in the ground there lived a hobbit. Not a
nasty, dirty, wet hole, filled with the ends of worms and an oozy
smell, nor yet a dry, bare, sandy hole with..."
pars = "Rect=10,10,190,190"
ca.Color = System.Drawing.Color.Yellow
ca.Width = 200
ca.Height = 200
ca.TextFont = "Times"
ca.TextSize = 18
ca.TextLength(txt, pars, len)
ca.DrawText(txt, pars)
ca.SaveAs(Server.MapPath("textlen.jpg"), "Quality=high")
Response.Write("Only able to fit " + len.ToString() +
" characters onto the canvas<br>")
Response.Write("<b>Original Text</b><br>
" + txt + "<br>")
Response.Write("<b>Drawn Text</b><br> "
+ Left(txt, len) + "<br>")
[C#]
Canvas ca = new Canvas();
int len = 0;
string txt = "In a hole in the ground there lived a hobbit.
Not a nasty, dirty, wet hole, filled with the ends of worms and
an oozy smell, nor yet a dry, bare, sandy hole with...";
string pars = "Rect=10,10,190,190";
ca.Color = System.Drawing.Color.Yellow;
ca.Width = 200;
ca.Height = 200;
ca.TextFont = "Times";
ca.TextSize = 18;
ca.TextLength(txt, pars, out len);
ca.DrawText(txt, pars);
ca.SaveAs(Server.MapPath("textlen.jpg"), "Quality=high");
Response.Write("Only able to fit " + len.ToString() +
" characters onto the canvas<br>");
Response.Write("<b>Original Text</b><br>
" + txt + "<br>");
Response.Write("<b>Drawn Text</b><br> "
+ txt.Substring(0, len) + "<br>");
The code draws out a piece of text onto a rather small canvas.
It also works out how much text was drawn onto the canvas and writes
it out as HTML. The image saved and the page output is shown below.
textlen.jpg
Only able to fit 106 characters onto the canvas
Original Text
In a hole in the ground there lived a hobbit. Not a nasty, dirty,
wet hole, filled with the ends of worms and an oozy smell, nor yet
a dry, bare, sandy hole with...
Drawn Text
In a hole in the ground there lived a hobbit. Not a nasty, dirty,
wet hole, filled with the ends of worms
|
|
|