Пример #1
0
        public void Modify(FileInfo cfgFile, FileInfo imgFile, int height, int fontHeight, int fontSize, string fontName)
        {
            FontConfig config = new FontConfig();

            config.FromCfg(cfgFile);

            if (config.Chr.Count == 0)
            {
                Console.WriteLine("未找到要修改的字体");
                return;
            }

            using (Bitmap img = new Bitmap(imgFile.FullName))
            {
                using (Graphics g = Graphics.FromImage(img))
                {
                    g.TextRenderingHint = TextRenderingHint.AntiAlias;
                    //定义字体,背景色,文字颜色,文字样式
                    Font  font      = new Font(new FontFamily(fontName), fontSize, GraphicsUnit.Pixel);
                    Brush back      = new SolidBrush(Color.Black);
                    Brush fontColor = new SolidBrush(Color.White);

                    StringFormat format = StringFormat.GenericTypographic;
                    format.Alignment     = StringAlignment.Center;
                    format.LineAlignment = StringAlignment.Center;

                    //遍历CHR,修改字体
                    foreach (CHR c in config.Chr)
                    {
                        string word = config.GetChar(c.UTF8);
                        //先清空原始位置的文字
                        g.FillRectangle(back, new Rectangle((int)c.X, (int)c.Y, c.Width, height));
                        //绘制文字
                        g.DrawString(word, font, fontColor, new RectangleF(c.X, c.Y, c.Width, fontHeight), format);
                    }
                }

                //保存图片为BMP格式
                string newFileName = imgFile.FullName.Replace(imgFile.Extension, "") + "_modify.bmp";
                img.Save(newFileName, ImageFormat.Bmp);
            }
        }
Пример #2
0
        public void Modify(FileInfo cfgFile, FileInfo imgFile, int height, int fontHeight, int fontSize, string fontName)
        {
            FontConfig config = new FontConfig();
            config.FromCfg(cfgFile);

            if (config.Chr.Count == 0)
            {
                Console.WriteLine("未找到要修改的字体");
                return;
            }

            using (Bitmap img = new Bitmap(imgFile.FullName))
            {
                using (Graphics g = Graphics.FromImage(img))
                {
                    g.TextRenderingHint = TextRenderingHint.AntiAlias;
                    //定义字体,背景色,文字颜色,文字样式
                    Font font = new Font(new FontFamily(fontName), fontSize, GraphicsUnit.Pixel);
                    Brush back = new SolidBrush(Color.Black);
                    Brush fontColor = new SolidBrush(Color.White);

                    StringFormat format = StringFormat.GenericTypographic;
                    format.Alignment = StringAlignment.Center;
                    format.LineAlignment = StringAlignment.Center;

                    //遍历CHR,修改字体
                    foreach (CHR c in config.Chr)
                    {
                        string word = config.GetChar(c.UTF8);
                        //先清空原始位置的文字
                        g.FillRectangle(back, new Rectangle((int)c.X, (int)c.Y, c.Width, height));
                        //绘制文字
                        g.DrawString(word, font, fontColor, new RectangleF(c.X, c.Y, c.Width, fontHeight), format);
                    }
                }

                //保存图片为BMP格式
                string newFileName = imgFile.FullName.Replace(imgFile.Extension, "") + "_modify.bmp";
                img.Save(newFileName, ImageFormat.Bmp);
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                PrintUseage();
                return;
            }

            switch (args[0].ToLower())
            {
                case "igg2img"://处理img的生成
                    if (args.Length != 4)
                    {
                        PrintUseage();
                        return;
                    }
                    FileInfo igg = new FileInfo(args[2]);
                    if (!igg.Exists)
                    {
                        Console.WriteLine("指定的p3igg文件不存在");
                        return;
                    }
                    Igg2Img p = new Igg2Img();
                    p.Produce(args[1], igg, (ConvertState)int.Parse(args[3]));
                    break;
                case "cfg2bin":
                    if (args.Length != 3)
                    {
                        PrintUseage();
                        return;
                    }
                    FileInfo cfgFile = new FileInfo(args[1]);
                    FontConfig c2b = new FontConfig();
                    c2b.FromCfg(cfgFile);
                    c2b.ToBin(args[2]);
                    break;
                case "bin2cfg":
                    if (args.Length != 3)
                    {
                        PrintUseage();
                        return;
                    }
                    FileInfo binFile = new FileInfo(args[1]);
                    FontConfig b2c = new FontConfig();
                    b2c.FromBin(binFile);
                    b2c.ToCfg(args[2]);
                    break;
                case "mf":
                    if (args.Length != 7)
                    {
                        PrintUseage();
                        return;
                    }
                    FileInfo mfCfgFile = new FileInfo(args[1]);
                    FileInfo mfImgFile = new FileInfo(args[2]);
                    int tileHeight = int.Parse(args[3]);
                    int fontHeight = int.Parse(args[4]);
                    int fontSize = int.Parse(args[5]);
                    string fontName = args[6];
                    FontModify fontModify = new FontModify();
                    fontModify.Modify(mfCfgFile, mfImgFile, tileHeight,fontHeight, fontSize, fontName);
                    break;
                default:
                    PrintUseage();
                    break;
            }
            Console.WriteLine("处理完成\r\n按任意键退出");
            Console.ReadKey();
        }
Пример #4
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                PrintUseage();
                return;
            }

            switch (args[0].ToLower())
            {
            case "igg2img":    //处理img的生成
                if (args.Length != 4)
                {
                    PrintUseage();
                    return;
                }
                FileInfo igg = new FileInfo(args[2]);
                if (!igg.Exists)
                {
                    Console.WriteLine("指定的p3igg文件不存在");
                    return;
                }
                Igg2Img p = new Igg2Img();
                p.Produce(args[1], igg, (ConvertState)int.Parse(args[3]));
                break;

            case "cfg2bin":
                if (args.Length != 3)
                {
                    PrintUseage();
                    return;
                }
                FileInfo   cfgFile = new FileInfo(args[1]);
                FontConfig c2b     = new FontConfig();
                c2b.FromCfg(cfgFile);
                c2b.ToBin(args[2]);
                break;

            case "bin2cfg":
                if (args.Length != 3)
                {
                    PrintUseage();
                    return;
                }
                FileInfo   binFile = new FileInfo(args[1]);
                FontConfig b2c     = new FontConfig();
                b2c.FromBin(binFile);
                b2c.ToCfg(args[2]);
                break;

            case "mf":
                if (args.Length != 7)
                {
                    PrintUseage();
                    return;
                }
                FileInfo   mfCfgFile  = new FileInfo(args[1]);
                FileInfo   mfImgFile  = new FileInfo(args[2]);
                int        tileHeight = int.Parse(args[3]);
                int        fontHeight = int.Parse(args[4]);
                int        fontSize   = int.Parse(args[5]);
                string     fontName   = args[6];
                FontModify fontModify = new FontModify();
                fontModify.Modify(mfCfgFile, mfImgFile, tileHeight, fontHeight, fontSize, fontName);
                break;

            default:
                PrintUseage();
                break;
            }
            Console.WriteLine("处理完成\r\n按任意键退出");
            Console.ReadKey();
        }