簡體   English   中英

如何以編程方式訪問字體

[英]How to access the font programmatically

我正在嘗試以編程方式訪問字體,因為我無法在共享主機上安裝字體

我用這個代碼

    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

但它始終顯示Arial字體。 如何使其顯示特定字體

謝謝

您不能在后台使用CSS嗎? 將自定義字體添加到“字體文件夾”中的解決方案中>將現有項目添加到Visual Studio中的字體文件夾中

示例:(使用我下載的隨機字體)

@font-face{
font-family: myFont;
src: url(/Fonts/Belleza-Regular.ttf);

}

.MyClass{
color:green;
font-family: myFont;
 }

然后在您的代碼中的任何位置附加此字體?

myControl.CssClass = "MyClass" etc..



可能是比您想要的略長的方法,並且僅當您要追加到控件時才有效,但是這樣可能是一個不錯的解決方法。

編輯:

也許像這樣? 使用自定義TTF字體繪制DrawString圖像

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM