本文整理汇总了C#中System.Drawing.Text.PrivateFontCollection.AddMemoryFont方法的典型用法代码示例。如果您正苦于以下问题:C# PrivateFontCollection.AddMemoryFont方法的具体用法?C# PrivateFontCollection.AddMemoryFont怎么用?C# PrivateFontCollection.AddMemoryFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Text.PrivateFontCollection
的用法示例。
在下文中一共展示了PrivateFontCollection.AddMemoryFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fonts
unsafe static Fonts() {
fonts = new PrivateFontCollection();
fixed (byte* data = Resources.Ubuntu)
fonts.AddMemoryFont((IntPtr)data, Resources.Ubuntu.Length);
fixed (byte* data = Resources.minecraft)
fonts.AddMemoryFont((IntPtr)data, Resources.minecraft.Length);
}
示例2: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
byte[] fontArray = Properties.Resources.OpenSans_ExtraBold;
int dataLength = Properties.Resources.OpenSans_ExtraBold.Length;
// ASSIGN MEMORY AND COPY BYTE[] ON THAT MEMORY ADDRESS
IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);
Marshal.Copy(fontArray, 0, ptrData, dataLength);
uint cFonts = 0;
AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);
PrivateFontCollection pfc = new PrivateFontCollection();
//PASS THE FONT TO THE PRIVATEFONTCOLLECTION OBJECT
pfc.AddMemoryFont(ptrData, dataLength);
//FREE THE "UNSAFE" MEMORY
Marshal.FreeCoTaskMem(ptrData);
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
Font font = new Font(pfc.Families[0], Font.Size, FontStyle.Regular);
e.Graphics.DrawString(Text, font, new SolidBrush(this.ForeColor), new PointF(20, 17), format);
}
示例3: FontCollection
private void FontCollection()
{
// Create the byte array and get its length
byte[] fontArray = Resources.gill_sans_ultra_bold_condensed;
int dataLength = Resources.gill_sans_ultra_bold_condensed.Length;
// ASSIGN MEMORY AND COPY BYTE[] ON THAT MEMORY ADDRESS
IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);
Marshal.Copy(fontArray, 0, ptrData, dataLength);
uint cFonts = 0;
AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);
PrivateFontCollection pfc = new PrivateFontCollection();
//PASS THE FONT TO THE PRIVATEFONTCOLLECTION OBJECT
pfc.AddMemoryFont(ptrData, dataLength);
//FREE THE "UNSAFE" MEMORY
Marshal.FreeCoTaskMem(ptrData);
ff = pfc.Families[0];
font = new Font(ff, 15f, FontStyle.Bold);
fontButtonRegular = new Font(ff, 25f, FontStyle.Bold);
fontButtonSelected = new Font(ff, 30f, FontStyle.Bold);
fontRankings = new Font(ff, 25f, FontStyle.Bold);
MyButton._normalFont = fontButtonRegular;
MyButton._hoverFont = fontButtonSelected;
}
示例4: LoadFont
internal static void LoadFont()
{
Fonts = new PrivateFontCollection();
// specify embedded resource name
Stream fontStream = new MemoryStream(Properties.Resources.futura_extrabold);
// create an unsafe memory block for the font data
System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length);
// create a buffer to read in to
byte[] fontdata = new byte[fontStream.Length];
//byte[] fontdata = InstagramScreenSaver.Properties.Resources.futura_extrabold;
// read the font data from the resource
fontStream.Read(fontdata, 0, (int)fontStream.Length);
// copy the bytes to the unsafe memory block
Marshal.Copy(fontdata, 0, data, (int)fontStream.Length);
// pass the font to the font collection
Fonts.AddMemoryFont(data, (int)fontStream.Length);
// close the resource stream
fontStream.Close();
// free up the unsafe memory
Marshal.FreeCoTaskMem(data);
}
示例5: ChatPreview
static unsafe ChatPreview()
{
Fonts = new PrivateFontCollection();
fixed( byte* fontPointer = Resources.MinecraftFont ) {
Fonts.AddMemoryFont( (IntPtr)fontPointer, Resources.MinecraftFont.Length );
}
MinecraftFont = new Font( Fonts.Families[0], 12, FontStyle.Regular );
ColorPairs = new[]{
new ColorPair(0,0,0,0,0,0),
new ColorPair(0,0,191,0,0,47),
new ColorPair(0,191,0,0,47,0),
new ColorPair(0,191,191,0,47,47),
new ColorPair(191,0,0,47,0,0),
new ColorPair(191,0,191,47,0,47),
new ColorPair(191,191,0,47,47,0),
new ColorPair(191,191,191,47,47,47),
new ColorPair(64,64,64,16,16,16),
new ColorPair(64,64,255,16,16,63),
new ColorPair(64,255,64,16,63,16),
new ColorPair(64,255,255,16,63,63),
new ColorPair(255,64,64,63,16,16),
new ColorPair(255,64,255,63,16,63),
new ColorPair(255,255,64,63,63,16),
new ColorPair(255,255,255,63,63,63)
};
}
示例6: AddFontFromResource
private void AddFontFromResource(PrivateFontCollection privateFontCollection, string fullFontResourceString)
{
var fontBytes = GetResourceBytes(fullFontResourceString);
var fontData = Marshal.AllocCoTaskMem(fontBytes.Length);
Marshal.Copy(fontBytes, 0, fontData, fontBytes.Length);
privateFontCollection.AddMemoryFont(fontData, fontBytes.Length); // Add font to collection.
Marshal.FreeCoTaskMem(fontData); // Do not forget to frees the memory block.
}
示例7: LoadFontFamily
/// <summary>
/// Načte font ze zdrojů.
/// </summary>
/// <param name="fontResourceData">Dara fontu ze zdrojů.</param>
/// <param name="fontCollection">Výstupní kolekce fontů s novým fontem.</param>
/// <returns>Vrací FontFamily.</returns>
public static unsafe FontFamily LoadFontFamily(byte[] fontResourceData, out PrivateFontCollection fontCollection)
{
fixed (byte* ptr = fontResourceData)
{
fontCollection = new PrivateFontCollection();
fontCollection.AddMemoryFont(new IntPtr(ptr), fontResourceData.Length);
return fontCollection.Families[0];
}
}
示例8: ProcessRequest
public void ProcessRequest(HttpContext context)
{
PrivateFontCollection pfc = new PrivateFontCollection();
string code = context.Request.QueryString["Code"];
if (String.IsNullOrEmpty(code)) throw new ArgumentNullException("Code");
// Get embedded font resource stream
Assembly aa = Assembly.GetExecutingAssembly();
string[] resourceNames = aa.GetManifestResourceNames();
Stream fontStream = aa.GetManifestResourceStream(resourceNames[0]);
if (fontStream == null) throw new ArgumentNullException("fontStream");
// Read font stream
byte[] fontData = new Byte[fontStream.Length];
fontStream.Read(fontData, 0, fontData.Length);
fontStream.Close();
// Pin array to get address
GCHandle handle = GCHandle.Alloc(fontData, GCHandleType.Pinned);
try {
IntPtr memIntPtr = Marshal.UnsafeAddrOfPinnedArrayElement(fontData, 0);
if (memIntPtr == null) throw new ArgumentNullException("memIntPtr");
// Add font to private collection and set font for use
pfc.AddMemoryFont(memIntPtr, fontData.Length);
Font barcode = new Font(pfc.Families[0], 44f);
// Determine width
Graphics gf = Graphics.FromImage(new Bitmap(100, 100));
SizeF size = gf.MeasureString(String.Format("*{0}*", code), barcode);
int width = (int)size.Width + 2;
const int height = 70;
using (Bitmap bm = new Bitmap(width, height))
using (Graphics g = Graphics.FromImage(bm))
using (MemoryStream ms = new MemoryStream()) {
Font text = new Font("Consolas", 12f);
PointF barcodeStart = new PointF(2f, 2f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush white = new SolidBrush(Color.White);
g.FillRectangle(white, 0, 0, width, height);
g.DrawString(String.Format("*{0}*", code), barcode, black, barcodeStart);
g.DrawString(code, text, black, new Rectangle(0, 46, width, 20), new StringFormat() { Alignment = StringAlignment.Center });
context.Response.ContentType = "image/png";
bm.Save(ms, ImageFormat.Png);
ms.WriteTo(context.Response.OutputStream);
}
} finally {
// Don't forget to unpin the array!
handle.Free();
}
}
示例9: ResourceFont
public ResourceFont(byte[] rawFont)
{
_font = new PrivateFontCollection();
using (var stream = new MemoryStream(rawFont))
{
_handle = GCHandle.Alloc(rawFont, GCHandleType.Pinned);
_fontPointer = _handle.AddrOfPinnedObject();
_font.AddMemoryFont(_fontPointer, (int)stream.Length);
uint dummy = 0;
AddFontMemResourceEx(_fontPointer, (uint)stream.Length, IntPtr.Zero, ref dummy);
}
}
示例10: PatternView
static PatternView()
{
pfc = new PrivateFontCollection();
byte[] fontdata = Properties.Resources.WHITRABT;
unsafe
{
fixed (byte* pFontData = fontdata)
{
pfc.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
}
}
}
示例11: LoadFont
public static Font LoadFont(Assembly a, string resource)
{
var fontStream = a.GetManifestResourceStream(resource);
var data = Marshal.AllocCoTaskMem((int)fontStream.Length);
var fontdata = new byte[fontStream.Length];
fontStream.Read(fontdata, 0, (int)fontStream.Length);
Marshal.Copy(fontdata, 0, data, (int)fontStream.Length);
var private_fonts = new PrivateFontCollection();
private_fonts.AddMemoryFont(data, (int)fontStream.Length);
fontStream.Close();
Marshal.FreeCoTaskMem(data);
return new Font(private_fonts.Families[0], 12);
}
示例12: loadFont
public void loadFont()
{
byte[] fontArray = Empire_World_Launcher.Properties.Resources.Diavlo2;
int dataLength = Empire_World_Launcher.Properties.Resources.Diavlo2.Length;
IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);
Marshal.Copy(fontArray, 0, ptrData, dataLength);
uint cFonts = 0;
AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);
PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddMemoryFont(ptrData, dataLength);
Marshal.FreeCoTaskMem(ptrData);
ff = pfc.Families[0];
}
示例13: LoadFontFamily
//Load font family from stream
public FontFamily LoadFontFamily(Stream stream)
{
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
IntPtr data = Marshal.AllocCoTaskMem((int)stream.Length);
Marshal.Copy(buffer, 0, data, (int)stream.Length);
PrvFontCollection = new PrivateFontCollection();
PrvFontCollection.AddMemoryFont(data, (int)stream.Length);
Marshal.FreeCoTaskMem(data);
return PrvFontCollection.Families[0];
}
示例14: LoadFontFamily
/* http://blog.andreloker.de/post/2008/07/03/Load-a-font-from-disk-stream-or-byte-array.aspx */
// load font family from byte array
public static FontFamily LoadFontFamily(byte[] buffer, out PrivateFontCollection fontCollection)
{
// pin array so we can get its address
var handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try {
var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
fontCollection = new PrivateFontCollection();
fontCollection.AddMemoryFont(ptr, buffer.Length);
return fontCollection.Families[0];
} finally {
// don't forget to unpin the array!
handle.Free();
}
}
示例15: setFonts
public void setFonts()
{
PrivateFontCollection fonts = new PrivateFontCollection();
byte[] fontData = Properties.Resources.Neverwinter;
IntPtr fontPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length);
System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
uint dummy = 0;
fonts.AddMemoryFont(fontPtr, Properties.Resources.Neverwinter.Length);
AddFontMemResourceEx(fontPtr, (uint)Properties.Resources.Neverwinter.Length, IntPtr.Zero, ref dummy);
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);
myFont = new Font(fonts.Families[0], 16.0F);
}