- Moderator
- #1
I'm working on a simple clothing designer, and I'm running into a bit of a stumbling block with fonts.
There doesn't seem to be a lot of documentation about the font in DrawString... I see reference to loading TrueType fonts by name into a FontFamily; other sites just load the font (which I'm assuming is a system font)... results are hit-and-miss... sometimes it renders the text as just "Arial"... sometimes it doesn't render it at all.
Here is a subroutine that I'm working on... it's obviously not finished, and not quite working properly yet.
Any thoughts or comments?
It is doing the layer insertion and so forth fine... the imgLayerx is a <asp:Image /> that I am setting the ImageURL to a temp file that I'm creating. I *believe* there may be a way to do that as a memorystream object so that I don't have to create all these temp files... but I'm not sure how I would do that either.
Any help/insight/directions to tutorials/etc. is GREATLY appreciated.
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg
There doesn't seem to be a lot of documentation about the font in DrawString... I see reference to loading TrueType fonts by name into a FontFamily; other sites just load the font (which I'm assuming is a system font)... results are hit-and-miss... sometimes it renders the text as just "Arial"... sometimes it doesn't render it at all.
Here is a subroutine that I'm working on... it's obviously not finished, and not quite working properly yet.
Any thoughts or comments?
Code:
Protected Sub RenderText(ByVal sText As String, ByVal x As Integer, ByVal y As Integer, ByVal sFont As String, ByVal FontSize As Single, ByVal Color As String, ByVal Layer As Integer, Optional ByVal Center As Boolean = False)
' sText = Text to render
' x and y = coordinates
' Font = font name - must exist in the font folder
' FontSize = Font Size
' Color = color of font
' Layer = Layer (1-5) to place rendered text. Usually 3, 4, or 5
' Center (default = false) = Should text be centered on X Position or not
Dim drawFont As New Font(sFont, FontSize)
' Dim bBrush As New SolidBrush(Drawing.Color.FromName(Color))
Dim col As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml(Color)
Dim bBrush As SolidBrush = New SolidBrush(col)
Dim newImage As New System.Drawing.Bitmap(500, 500)
Dim objGraphics As System.Drawing.Graphics
objGraphics = System.Drawing.Graphics.FromImage(newImage)
objGraphics.Clear(Drawing.Color.Transparent)
If Center = False Then
objGraphics.DrawString(sText, drawFont, bBrush, New Point(x, y))
Else
' Haven't even thought this out yet...
End If
Dim tmpFile As String = GetTempFile()
newImage.Save(Server.MapPath(tmpFile))
Select Case Layer
Case 1
imgLayer1.ImageUrl = tmpFile
Case 2
imgLayer2.ImageUrl = tmpFile
Case 3
imgLayer3.ImageUrl = tmpFile
Case 4
imgLayer4.ImageUrl = tmpFile
Case 5
imgLayer5.ImageUrl = tmpFile
End Select
End Sub
It is doing the layer insertion and so forth fine... the imgLayerx is a <asp:Image /> that I am setting the ImageURL to a temp file that I'm creating. I *believe* there may be a way to do that as a memorystream object so that I don't have to create all these temp files... but I'm not sure how I would do that either.
Any help/insight/directions to tutorials/etc. is GREATLY appreciated.
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg