我想在C#中使用稱爲黑玫瑰的字體創建一個圖像。圖像被創建,但不是我想要的字體。這裏是我的代碼,我用來創建圖像:新System.Drawing.Font代碼隱藏
protected void Page_Load(object sender, EventArgs e)
{
string MoneyImg = "1000";
Bitmap bitmap = new Bitmap(MoneyImg.Length * 40, 150);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
Font oFont = new System.Drawing.Font("BLACKR", 20);
PointF point = new PointF(2f, 2f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush white = new SolidBrush(Color.White);
graphics.FillRectangle(white, 0, 0, bitmap.Width, bitmap.Height);
graphics.DrawString("$" + MoneyImg , oFont, black, point);
}
}
我試圖改變這一行
Font oFont = new System.Drawing.Font("BLACKR", 20);
到
Font oFont = new System.Drawing.Font("BLACKR.TTF", 20);
,但不有所作爲。我知道字體文件位於正確的位置,因爲我使用CSS樣式進行了測試,並且顯示正常。這裏是CSS代碼和截圖。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
@font-face
{
font-family: Black Rose; src: url('BLACKR.TTF');
}
h3 {
font-family: 'Black Rose'
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="Image1" runat="server" />
<br />
<h3>This is what the Image Font Looks Like</h3>
</div>
</form>
</body>
</html>