Unable to use certain Fonts programatically in ASP.Net

Posted by TooFat on Stack Overflow See other posts from Stack Overflow or by TooFat
Published on 2010-05-06T14:30:53Z Indexed on 2010/05/06 14:38 UTC
Read the original article Hit count: 231

Filed under:
|
|

I am trying to programatically create a bitmap with a specified font in ASP.Net. The idea is that the text, font name, size color etc. will be passed in from variables and a bitmap of the text using the font etc will be returned. However, I have been finding that I am only able to do so using the following code with certain fonts.

   <div>
    <%
     string fontName = "Segoe Script"; //Change Font here
     System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(100, 100);
     System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp);
     System.Drawing.Font fnt = new System.Drawing.Font(fontName, 20);
     System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
    graph.DrawString("Help", fnt, brush, new System.Drawing.Point(10, 10));

    bmp.Save(@"C:\Development\Path\image1.bmp");
    this.Image1.ImageUrl = "http://mysite/Images/image1.bmp";
    %>
 <asp:Label ID="Label1" runat="server" Text="Label" Font-Names="Segoe Script">  <%Response.Write("Help"); %></asp:Label> //Change font here
<asp:Image ID="Image1" runat="server" />
</div>

If I change the font name in the areas indicated by the comments to Arial or Verdana both the image and the label appear with the correct font. If however, I change the font name in both locations to something "Segoe Script" the Label will show up in Segoe Script but the image is in what looks like Arial.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#