Exemplo n.º 1
0
        protected static void CreateCharacter(Font f, CharData data, string fontFamily, float fontSize, string ch, FontStyle style)
        {
            using (var ghelper = Graphics.FromImage(fontHelper))
            {
                StringFormat format = StringFormat.GenericTypographic;

                var size = ghelper.MeasureString(ch, f, 0, format);
                data.size     = new Vector2(size.Width, size.Height);
                data.bearing  = f.GetHeight();
                data.style    = style;
                data.fontSize = fontSize;

                if (Math.Ceiling(size.Width) <= 0 || Math.Ceiling(size.Height) <= 0)
                {
                    return;
                }

                using (Bitmap b = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    using (var g = Graphics.FromImage(b))
                    {
                        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                        g.DrawString(ch, f, WhiteColor, new PointF(0, 0), format);
                    }

                    RawBitmap bit = RawBitmap.FromBitmap(b);
                    data.texture = bit;
                }
            }
        }
Exemplo n.º 2
0
        private void LoadBitmap()
        {
            try
            {
                if (archive != null && !string.IsNullOrEmpty(relativePath) && Resource)
                {
                    archive.Open();
                    List <MTGArchive.ArchiveFile> files = archive.GetAvailableFiles();

                    var m = files.Find(f => f.path.Equals(relativePath));
                    if (m != null)
                    {
                        using (Stream ms = m.GetStream())
                            using (Bitmap bmp = (Bitmap)Bitmap.FromStream(ms))
                            {
                                if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                                {
                                    width  = bmp.Width;
                                    height = bmp.Height;
                                    brush  = RawBitmap.FromBitmap(bmp);
                                    archive.Close();
                                    return;
                                }
                            }
                    }

                    archive.Close();
                }

                if (!string.IsNullOrEmpty(path) && File.Exists(path))
                {
                    using (Bitmap bmp = (Bitmap)Bitmap.FromFile(path))
                    {
                        if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                        {
                            width  = bmp.Width;
                            height = bmp.Height;

                            brush = RawBitmap.FromBitmap(bmp);
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(relativePath) && ParentGraph != null && !string.IsNullOrEmpty(ParentGraph.CWD) && File.Exists(System.IO.Path.Combine(ParentGraph.CWD, relativePath)))
                {
                    using (Bitmap bmp = (Bitmap)Bitmap.FromFile(System.IO.Path.Combine(ParentGraph.CWD, relativePath)))
                    {
                        if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                        {
                            width  = bmp.Width;
                            height = bmp.Height;

                            brush = RawBitmap.FromBitmap(bmp);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }