2019年第13的小工具程序--使用bmfont生成不同颜色的文字图片

具体问题:

由于bmfont本身不支持生成其他颜色的图片. 自己写了一个工具来弥补他的功能
 

Channel options

glyph : The channel will be set according to the glyph geometry. A value of 1 means the pixel is within the glyph.
outline : The channel will be set according to the outline geometry. A value of 1 means the pixel is within the outline or glyph.
glyph + outline : The value is encoded to allow separation of glyph and outline. A value of 0.5 means the pixel is within the outline, but not within the glyph. A value of 1 means the pixel is within the glyph.
one : All pixels in the channel will be set to 1.
zero : All pixels in the channel will be set to 0.
Some of the more common choices are:

32bit white glyphs with black outline: alpha = outline, red = green = blue = glyph
32bit white glyphs without outline: alpha = glyph, red = green = blue = one
packed textures with glyph and outline encoded in 8 bits: alpha = glyph + outline
packed textures with glyphs without outline: alpha = glyph

bmfont下载地址

http://www.angelcode.com/products/bmfont/

 

抓取多国语言中的字符串

因为多国语言翻译在不同的配表中, 我们先自动抓取里面的文字

            string jsonstr = sPath + "/" + language + ".json";
            FindChar.Clear();

            string strIgr = textBoxIng.Text;
            string[] arrIgr = strIgr.Split(',');
            List ListIgr = new List() { };
           
            for (int i = 0; i < arrIgr.Length; i++)
            {
                strIgr = arrIgr[i].Trim();
                if (strIgr.Length >0 && ListIgr.Contains(strIgr) ==false)
                {
                    ListIgr.Add(strIgr);
                    break;
                }
            }

            checkchar(basestr);

            StreamReader sr = new StreamReader(jsonstr, Encoding.UTF8);
            string line = "";
       
            while ((line = sr.ReadLine()) != null)
            {
                bool findIgr = false;
                for (int i = 0; i < ListIgr.Count; i++)
                {
                    if (line.Contains(ListIgr[i]))
                    {
                        findIgr = true;
                        break;
                    }
                }
                if (findIgr == true)
                {
                    continue;
                }

                checkchar(line);
            }
            string FindString = "";
            for (int i = 0; i < FindChar.Count; i++)
            {
                FindString += FindChar[i];
                
            }

            sr.Close();

            string WordTxt = gamePath+ "/BMFont/tmp/" + language + ".txt";
            if (File.Exists(WordTxt))
            {
                File.Delete(WordTxt);
            }

            FileStream fs = new FileStream(WordTxt, FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter srr = new StreamWriter(fs, Encoding.UTF8);
            srr.WriteLine(FindString);//开始写入值
            srr.Close();
            fs.Close();

 

使用命令生成图片

用命令行来实现导出,大大提升效率

  string sPath = gamePath + "\\BMFont";
            sPath = sPath.Replace("\\", "/");
            Process process = new Process();
            process.StartInfo.FileName = "" + sPath + "/bmfont.exe";
            process.StartInfo.Arguments = " -t \"" + sPath + "/tmp/"+ language + ".txt\" -c \"" + sPath + "/tmp/" + language + ".bmfc\" -o \"" + sPath + "/tmp/" + language + ".fnt\"";


            //隐藏DOS窗口  
            //process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.Start();
            process.WaitForExit();
            process.Close();

命令解释:

-c fontconfig.bmfc : Names the configuration file with the options for generating the font.
-o outputfile.fnt : Names of the output font file.
-t textfile.txt : Optional argument that names a text file. All characters present in the text file will be added to the font.

颜色导出

这里使用C或其他语言,模仿ps的图片处理功能进行颜色设置.

功能截图

主界面

2019年第13的小工具程序--使用bmfont生成不同颜色的文字图片_第1张图片

生成多过语言

2019年第13的小工具程序--使用bmfont生成不同颜色的文字图片_第2张图片

根据设定颜色.生成不同颜色的文件

2019年第13的小工具程序--使用bmfont生成不同颜色的文字图片_第3张图片

 

你可能感兴趣的:(C#)