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

本文介绍了一种增强bmfont工具的方法,通过自制工具弥补了其不支持生成彩色图片的功能,并展示了如何自动抓取多国语言翻译中的字符串,以及使用命令行批量生成字体图片的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

具体问题:

由于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<string> ListIgr = new List<string>() { };
           
            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的图片处理功能进行颜色设置.

功能截图

主界面

生成多过语言

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值