Integration method
suggest changeAddMemoryFont keeps using the block you allocate, and the FontFamily stays valid only while that PrivateFontCollection is alive. Keep both for as long as you draw with the font. Freeing the block here, or dropping the collection, makes the family unusable.
private static readonly PrivateFontCollection Fonts = new PrivateFontCollection();
public static FontFamily GetResourceFontFamily(byte[] fontbytes)
{
IntPtr fontMemPointer = Marshal.AllocCoTaskMem(fontbytes.Length);
Marshal.Copy(fontbytes, 0, fontMemPointer, fontbytes.Length);
Fonts.AddMemoryFont(fontMemPointer, fontbytes.Length);
return Fonts.Families[Fonts.Families.Length - 1];
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents