Bonjour,
J'ai tenté de charger une police depuis une ressource incorporée, mais cela ne fonctionne pas
Voilà comment je procède:
Par contre en chargeant la même police via le fichier, ça fonctionne:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 PrivateFontCollection pfcFontCollec = new PrivateFontCollection(); Assembly asm = Assembly.GetEntryAssembly(); string[] result = asm.GetManifestResourceNames(); Stream fontStream = asm.GetManifestResourceStream("TripleTriad.visitor1.ttf"); // buffer byte[] fontData = new byte[fontStream.Length]; // read fontStream.Read(fontData, 0, (int)fontStream.Length); IntPtr data = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) * fontData.Length); // copy to unsafe memory block Marshal.Copy(fontData, 0, data, fontData.Length); // add to font collection pfcFontCollec.AddMemoryFont(data, fontData.Length); // clean up fontStream.Close(); Marshal.FreeHGlobal(data); Font testFont = new Font(pfcFontCollec.Families[0], 10, FontStyle.Regular);
Si vous avez une autre idée ou si vous avez remarqué une faute, merci de m'aider.
Code : Sélectionner tout - Visualiser dans une fenêtre à part pfcFontFileCollec.AddFontFile("visitor1.ttf");
Partager