0

i got a request to change the Font family of a string that im drawing on a rectangle and after in an image , my question is : How? , i know how to add a custom font on the html but this time im assigning it by code behind like this :

   `StringFormat stringformat2 = new StringFormat();
    stringformat2.Alignment = StringAlignment.Center;
    stringformat2.LineAlignment = StringAlignment.Center;

    Color StringColor2 = System.Drawing.ColorTranslator.FromHtml("#ffffff");

     graphicsImage.DrawString(Str_TextOnImage2, new Font("arial", 25,
                    FontStyle.Bold), new SolidBrush(StringColor2), rect,
                    stringformat2); Response.ContentType = "image/png";`

I need to change the "Arial" to a google font named Open Sans. I really appreciate if anyone can help in what direction should i go or what article should i read to achieve this . thanks in advance , im currently working on c# asp.net visual studio.

  • Do you have that Font file(s)? See these answers if you do: [addFontFile from Resources](https://stackoverflow.com/a/23658552/7444103). – Jimi Nov 21 '18 at 00:20
  • And [Adding custom font to asp.net application](https://stackoverflow.com/questions/24740024/adding-custom-font-to-asp-net-application). Your Open Sans font. – Jimi Nov 21 '18 at 00:30
  • Thanks , solved downloading the ttf file and using the answer N°3 – Roberto González Moreno Nov 21 '18 at 12:35

0 Answers0