Issue
I'm trying to access to a font programmatically, because i cant install fonts on the sharing hosting
I use this code
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim collection As New PrivateFontCollection()
collection.AddFontFile(Server.MapPath("~\ShadowsIntoLight.ttf"))
Dim image As New Bitmap(500, 500)
Dim g As Graphics = Graphics.FromImage(image)
Dim RedBrush As New SolidBrush(Color.Black)
Dim drawFont As New Font("Shadows Into Light", 36)
g.DrawString("the lazy fox jumped over the brown log", drawFont, RedBrush, 0, 100)
Dim path As String = Server.MapPath("~/image.png")
image.Save(path, ImageFormat.Png)
g.Dispose()
image.Dispose()
Response.Write("<img src=""image.png""/>")
End Sub
but it always displays the Arial font. How can I make it display the specific font
Thank you
Solution
Could you not use CSS in the background? Add the custom font to your solution in a 'Fonts folder' > add existing item to fonts folder in visual studio
Example: (Using a random font I downloaded)
@font-face{
font-family: myFont;
src: url(/Fonts/Belleza-Regular.ttf);
}
.MyClass{
color:green;
font-family: myFont;
}
Then append this font anywhere within your code?
myControl.CssClass = "MyClass" etc..
Might be a slightly longer way than you wanted and would only work if you're appending to controls and such however might be a nice workaround.
Edit:
maybe something like this? Using custom TTF font for DrawString image rendering
Answered By - dan6657 Answer Checked By - Marie Seifert (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.