When you do a verification code or logo watermark, you sometimes want to use some special fonts... however, it is very difficult for us to use a VM to ask the server provider to install one or more fonts on the server ....
So I had to find the answer on csdn .. however, if a good solution cannot be found for a long time, I had to myself on msdn. search for information related to font, one by one .... finally, let me find a keyword addfontfile (stringFilename), a bright spot.Privatefontcollection class, finally found the solution...
Privatefontcollection class:Provides a font family set based on client applications.ProgramProvided font file generation.
That is to say, this is a set. We only need to add our own font to this set and then call it. The following is the method to call.
Call Method
System. Drawing. Text. privatefontcollection PFC = New System. Drawing. Text. privatefontcollection ();
String Fontpath = Server. mappath ( " ~ /Fonts/mytholog. TTF " ); // Font file path relative to the virtual directory
PFC. addfontfile (fontpath );
Font font = New System. Drawing. Font (PFC. Families [ 0 ], 20 ); // Now we can use the font ~~
URL: http://blog.csdn.net/conanlwl/archive/2007/10/11/1820812.aspx
----------------------------------------
After actual use, no problem at all
This is very helpful for generating text images on the server. Thanks to the original author for sharing them.
New questions:
After one website migration, you cannot use a Custom font, and no error is reported. No reason is found.
After testing, it is found that the Font File Uploaded by FTP is damaged, and the file upload mode is changed to normal.