The
AddFontFile
method expects the path of a physical file on disk. You cannot pass in a
pack:
URI, because it doesn't understand that format. And you cannot just call
.ToString()
on a
Stream
, since that won't produce any meaningful information.
You need to extract your font file to a temporary file, and pass the path to that file to the
AddFontFile
method.
string tempPath = Path.GetTempPath();
string fileName = "WpfApp5.FNT.BTITRBD.TTF";
string fontPath = Path.Combine(tempPath, fileName);
if (!File.Exists(fontPath))
{
using (var stream = Assembly.GetEntryAssembly().GetManifestResourceStream(fileName))
using (var output = File.Create(fontPath))
{
stream.CopyTo(output);
}
}
StiFontCollection.AddFontFile(fontPath);