public static GetFixed ( int font ) : |
||
font | int | |
return |
public unsafe static Bitmap DrawText(int fontId, string text, short hueId) { ASCIIFont font = ASCIIFont.GetFixed(fontId); Bitmap result = new Bitmap(font.GetWidth(text), font.Height); BitmapData surface = result.LockBits(new Rectangle(0, 0, result.Width, result.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); int dx = 0; for (int i = 0; i < text.Length; ++i) { Bitmap bmp = font.GetBitmap(text[i]); BitmapData chr = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); for (int dy = 0; dy < chr.Height; ++dy) { byte *src = ((byte *)chr.Scan0) + (chr.Stride * dy); byte *dest = (((byte *)surface.Scan0) + (surface.Stride * (dy + (font.Height - chr.Height)))) + (dx << 2); for (int k = 0; k < chr.Width; ++k) { *dest++ = *src++; *dest++ = *src++; *dest++ = *src++; *dest++ = *src++; } } dx += chr.Width; bmp.UnlockBits(chr); } result.UnlockBits(surface); hueId = (short)((hueId & 0x3FFF) - 1); if (hueId >= 0 && hueId < Hues.List.Length) { Hue hueObject = Hues.List[hueId]; if (hueObject != null) { hueObject.ApplyTo(result, ((hueId & 0x8000) == 0)); } } return(result); }
/// <summary> /// Draws Text with font in Bitmap and returns /// </summary> /// <param name="fontId"></param> /// <param name="text"></param> /// <returns></returns> public static Bitmap DrawText(int fontId, string text) { ASCIIFont font = ASCIIFont.GetFixed(fontId); Bitmap result = new Bitmap(font.GetWidth(text) + 2, font.Height + 2); int dx = 2; int dy = font.Height + 2; using (Graphics graph = Graphics.FromImage(result)) { for (int i = 0; i < text.Length; ++i) { Bitmap bmp = font.GetBitmap(text[i]); graph.DrawImage(bmp, dx, dy - bmp.Height); dx += bmp.Width; } } return(result); }
/// <summary> /// Draws Text with font in Bitmap and returns /// </summary> /// <param name="fontId"></param> /// <param name="text"></param> /// <returns></returns> public static Bitmap DrawText(int fontId, string text) { ASCIIFont font = ASCIIFont.GetFixed(fontId); var result = new Bitmap(font.GetWidth(text) + 2, font.Height + 2); int dx = 2; int dy = font.Height + 2; using (Graphics graph = Graphics.FromImage(result)) { foreach (var character in text) { Bitmap bmp = font.GetBitmap(character); graph.DrawImage(bmp, dx, dy - bmp.Height); dx += bmp.Width; } } return(result); }