Hi @Anjali Agarwal ,
If you use System.Drawing
, then you need to install this font in your computer. in the msdn documents on the Font Class you can see: If you attempt to use a font that is not supported, or the font is not installed on the machine that is running the application, the Microsoft Sans Serif font will be substituted.
You can copy your journal.ttf
file to the computer's C:\Windows\Fonts
directory, which will install your fonts on the computer.
In addition, Font
cannot recognize the path, it can only recognize the corresponding familyName
:
So you just need to pass the name of the font after installing it:
new Font("Journal", 100, FontStyle.Regular)
Result:
If you don't want to install fonts, and just want to get fonts through the corresponding path, you can use GrapeCity.Documents.Imaging Nuget Package. Below is mt test code, you can refer to it.
//Create GcBitmap
var bmp = new GcBitmap(1024, 1024, true, 96, 96);
//Create a graphics for drawing
GcBitmapGraphics g = bmp.CreateGraphics();
//Add a radial gradient
RadialGradientBrush r = new RadialGradientBrush(Color.Beige,
Color.RosyBrown, new PointF(0.5f, 0.5f), true);
//Draw a rectangle
var rc = new RectangleF(0, 0, bmp.Width, bmp.Height);
//Fill the rectangle using specified brush
g.FillRectangle(rc, r);
// Create a text format for the "Hello World!" string:
TextFormat tf = new TextFormat()
{
Font = Font.FromFile(Path.Combine(_environment.WebRootPath, "Font/JOURNAL.TTF")),
FontSize = 36
};
//Draw the string (text)
g.DrawString("Hello World!", tf, rc, TextAlignment.Center,
ParagraphAlignment.Center, false);
//Save bitmap
bmp.SaveAsJpeg(Path.Combine(_environment.WebRootPath, "Image/Helloworld.jpg"));
Result:
For more detail about GrapeCity.Documents.Imaging, you can refer to this document.
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
Chen Li