/// <summary> /// Draws an 8x8 character cell on the bitmap. /// </summary> /// <remarks> /// Might want a way to specify that the background shouldn't be drawn at all. /// </remarks> /// <param name="vb">Bitma to draw on.</param> /// <param name="ch">Character to draw.</param> /// <param name="xc">X coord of upper-left pixel.</param> /// <param name="yc">Y coord of upper-left pixel.</param> /// <param name="foreColor">Foreground color index.</param> /// <param name="backColor">Background color index.</param> public static void DrawChar(VisBitmap8 vb, char ch, int xc, int yc, byte foreColor, byte backColor) { int origXc = xc; int[] charBits = Font8x8.GetBitData(ch); for (int row = 0; row < 8; row++) { int rowBits = charBits[row]; for (int col = 7; col >= 0; col--) { if ((rowBits & (1 << col)) != 0) { vb.SetPixelIndex(xc, yc, foreColor); } else { vb.SetPixelIndex(xc, yc, backColor); } xc++; } xc = origXc; yc++; } }
/// <summary> /// Gets a rendered dispay buffer of the specified string /// </summary> /// <param name="message">The message</param> /// <returns>The buffer</returns> public byte[][] Render(string message) { Font8x8.Character character = null; message = (message ?? string.Empty); var buffer = CreateBuffer(message.Length); for (int charIndex = 0; charIndex < message.Length; charIndex++) { var characterToRender = message[charIndex]; character = Font8x8.GetCharacter(characterToRender); if (character == null) { character = Font8x8.GetCharacter(' '); } if (character == null) { throw new NotSupportedException(string.Format("Character '{0}' is not supported", characterToRender)); } for (var r = 0; r < this.Rows; r++) { buffer[r][charIndex] = character.Bitmap[r]; } } return(buffer); }