當前位置: 首頁>>代碼示例>>C#>>正文


C# PrivateFontCollection.AddMemoryFont方法代碼示例

本文整理匯總了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);

        }
開發者ID:ninedrafted,項目名稱:MCForge-Vanilla,代碼行數:10,代碼來源:Fonts.cs

示例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);
        }
開發者ID:krzycho1717,項目名稱:TV-Calendar,代碼行數:29,代碼來源:ArrowIcon.cs

示例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;
        }
開發者ID:Gago993,項目名稱:TriGame,代碼行數:30,代碼來源:StartScreen.cs

示例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);
        }
開發者ID:jsolarz,項目名稱:InstagramScreenSaver,代碼行數:30,代碼來源:FontsService.cs

示例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)
            };
        }
開發者ID:Bedrok,項目名稱:800craft,代碼行數:27,代碼來源:ChatPreview.cs

示例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.
 }
開發者ID:dteunkenstt,項目名稱:SVG,代碼行數:8,代碼來源:PrivateFontsTests.cs

示例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];
     }
 }
開發者ID:mimic2300,項目名稱:WormsGL,代碼行數:15,代碼來源:Util.cs

示例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();
            }
        }
開發者ID:timhobbs,項目名稱:BarcodeHttpHandler,代碼行數:54,代碼來源:BarcodeHandler.cs

示例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);                
     }
 }
開發者ID:jgera,項目名稱:FerretLib.WinForms,代碼行數:12,代碼來源:ResoureceFontLoader.cs

示例10: PatternView

 static PatternView()
 {
     pfc = new PrivateFontCollection();
     byte[] fontdata = Properties.Resources.WHITRABT;
     unsafe
     {
         fixed (byte* pFontData = fontdata)
         {
             pfc.AddMemoryFont((System.IntPtr)pFontData, fontdata.Length);
         }
     }
 }
開發者ID:AugustoRuiz,項目名稱:WYZTracker,代碼行數:12,代碼來源:PatternView.cs

示例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);
 }
開發者ID:HaKDMoDz,項目名稱:eStd,代碼行數:13,代碼來源:Tools.cs

示例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];
 }
開發者ID:RiiggedMPGH,項目名稱:Owl-Realms-Source,代碼行數:13,代碼來源:Form1.cs

示例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];
        }
開發者ID:wischi-chr,項目名稱:Wischis-Minecraft-Launcher,代碼行數:14,代碼來源:Form1.cs

示例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();
     }
 }
開發者ID:jpiolho,項目名稱:sledge,代碼行數:16,代碼來源:CustomFont.cs

示例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);
        }
開發者ID:Salvasdf,項目名稱:FirstCSharpGame,代碼行數:14,代碼來源:Metodos.cs


注:本文中的System.Drawing.Text.PrivateFontCollection.AddMemoryFont方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。