public void Draw_Char() { Bitmap image = NFTR.Get_Char(tiles, depth, width, height, rotateMode, palette, 10); // Draw the grid Graphics graphic = Graphics.FromImage(image); for (int h = 0; h < height * 10; h += 10) { graphic.DrawLine(Pens.Red, 0, h, width * 10, h); } for (int w = 0; w < width * 10; w += 10) { graphic.DrawLine(Pens.Red, w, 0, w, height * 10); } picFont.Image = image; }
private void txtBox_TextChanged(object sender, EventArgs e) { Bitmap image = new Bitmap(picText.Width, picText.Height); Graphics graphic = Graphics.FromImage(image); graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; int width = 0; int height = 0; for (int i = 0; i < txtBox.Text.Length; i++) { if (txtBox.Text[i] == '\n') { width = 0; height += font.plgc.tile_height; continue; } byte[] codes = new byte[1]; if (comboEncoding.SelectedIndex == 2) { codes = Encoding.GetEncoding("shift_jis").GetBytes(new char[] { txtBox.Text[i] }).Reverse().ToArray(); } else if (comboEncoding.SelectedIndex == 1) { codes = Encoding.GetEncoding("utf-16").GetBytes(new char[] { txtBox.Text[i] }); } else if (comboEncoding.SelectedIndex == 0) { codes = Encoding.UTF8.GetBytes(new char[] { txtBox.Text[i] }); } else if (comboEncoding.SelectedIndex == 3) { codes = Encoding.GetEncoding(1252).GetBytes(new char[] { txtBox.Text[i] }); } int charCode = (codes.Length == 2 ? BitConverter.ToUInt16(codes, 0) : codes[0]); int tileCode; if (!charTile.TryGetValue(charCode, out tileCode)) { width += font.plgc.tile_width; continue; } width += font.hdwc.info[tileCode].pixel_start; Bitmap charImage = NFTR.Get_Char(font, tileCode, palette); charImage.MakeTransparent(this.palette[0]); graphic.DrawImageUnscaled(charImage, width, height); width += font.hdwc.info[tileCode].pixel_length - font.hdwc.info[tileCode].pixel_start; if (width + font.plgc.tile_width > image.Width) { width = 0; height += font.plgc.tile_height; } } picText.Image = image; }