I'm trying to dynamically write text to an image, but I would like to boldface a selected word in the sentence. What I did is separate the string into three strings, the first part, the word to be boldfaced, and the remainder of the sentence. When I attempt to draw them onto the image (.DrawString()
), however, they don't concatenate, but rather overwrite one another. Is there any way I can reconstruct a sentence (boldfacing a middle word) on an image?
Thanks!
EDIT: Example code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim w As Word = Word.GetLastPublishedWord()
Dim wordForm As String = Word.FindWordForm(w.Word, w.Sentence, Word.RegexOutputType.StandardString)
Dim firstPart As String = Left(w.Sentence, w.Sentence.IndexOf(wordForm))
Dim lastPart As String = Right(w.Sentence, (w.Sentence.Length - firstPart.Length - wordForm.Length))
Dim sig As Image = Image.FromFile(Server.MapPath(ResolveUrl("~/images/sig.jpg")))
Dim text As Graphics = Graphics.FromImage(sig)
text.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
Dim sentenceRec As New RectangleF(0, 0, 400, 75)
Dim tagRec As New RectangleF(250, 75, 150, 25)
text.DrawString(firstPart, New Font("Arial", 12, FontStyle.Regular), SystemBrushes.WindowText, sentenceRec)
text.DrawString(wordForm, New Font("Arial", 12, FontStyle.Bold), SystemBrushes.WindowText, sentenceRec)
text.DrawString(lastPart, New Font("Arial", 12, FontStyle.Regular), SystemBrushes.WindowText, sentenceRec)
Response.ContentType = "image/jpeg"
sig.Save(Response.OutputStream, ImageFormat.Jpeg)
sig.Dispose()
text.Dispose()
End Sub