Exemple #1
0
        /// <summary>
        /// 写字库小图片
        /// </summary>
        private void WriteTtfFontPics()
        {
            List <byte> charIndexMap = new List <byte>();
            //List<byte> charPngData = new List<byte>();

            // 生成Ascii码文字
            StringBuilder sb = new StringBuilder();

            for (int i = 0x20; i <= 0x7e; i++)
            {
                sb.Append(Encoding.GetEncoding(932).GetString(new byte[] { (byte)i }));
            }

            char[] yiJiChTxt = sb.Append(Util.CreateOneLevelHanzi()).ToString().ToCharArray();
            //char[] yiJiChTxt = sb.Append("手柄存保映射卡了到游戏的设槽动插忆失记有没败上自载加档定读按右从置取状开态镜像备指不键启关经在发闭现始前左时音制目频体具典型重个支录功持打是要选当一择帧数默认信空找入显输新示未大玩初钮类较误错息通化成常各限跳编译续继请确先出作种组退返执过行释解心吗回需核视比准量正最标震网只这能而须小必着另试系统络西放东无强缩幕屏模抖式接生连被还已控总盘器换").ToString().ToCharArray();
            ImgInfo imgInfo = new ImgInfo(24, 24);

            imgInfo.BlockImgH  = 24;
            imgInfo.BlockImgW  = 24;
            imgInfo.NeedBorder = false;
            imgInfo.FontStyle  = FontStyle.Regular;

            // 显示进度条
            this.ResetProcessBar(yiJiChTxt.Length);

            int charIndex = 0;

            foreach (char chChar in yiJiChTxt)
            {
                imgInfo.NewImg();
                imgInfo.CharTxt  = chChar.ToString();
                imgInfo.XPadding = 0;
                imgInfo.YPadding = 0;
                ImgUtil.WriteBlockImg(imgInfo);


                // 保存字符映射表信息
                //byte[] byChar = Encoding.UTF8.GetBytes(imgInfo.CharTxt);
                byte[] byChar    = Encoding.BigEndianUnicode.GetBytes(imgInfo.CharTxt);
                byte[] byCurChar = new byte[4];
                Array.Copy(byChar, 0, byCurChar, 0, byChar.Length);
                this.SetCharPadding(byCurChar, imgInfo.Bmp);
                charIndexMap.AddRange(byCurChar);

                //charIndex = charPngData.Count;
                //charIndexMap.Add((byte)(charIndex >> 24 & 0xFF));
                //charIndexMap.Add((byte)(charIndex >> 16 & 0xFF));
                //charIndexMap.Add((byte)(charIndex >> 8 & 0xFF));
                //charIndexMap.Add((byte)(charIndex & 0xFF));

                // 保存文字图片信息
                byte[] byCharFont = Util.ImageEncode(imgInfo.Bmp, "I4");
                //charPngData.AddRange(byCharFont);

                charIndexMap.AddRange(byCharFont);

                // 更新进度条
                this.ProcessBarStep();
            }

            // 隐藏进度条
            this.CloseProcessBar();

            File.WriteAllBytes(@"E:\Study\MySelfProject\Hanhua\fontTest\ZhBufFont.dat", charIndexMap.ToArray());
            //File.WriteAllBytes(@"E:\Study\MySelfProject\Hanhua\fontTest\CharPosMap.dat", charIndexMap.ToArray());
            //File.WriteAllBytes(@"E:\Study\MySelfProject\Hanhua\fontTest\CharPng.dat", charPngData.ToArray());
        }
Exemple #2
0
        private void WriteMyPsFont(List <int> allZhTxt)
        {
            List <byte> charIndexMap = new List <byte>();
            //List<byte> charInfoMap = new List<byte>();

            ImgInfo imgInfo = new ImgInfo(24, 24);

            imgInfo.BlockImgH  = 24;
            imgInfo.BlockImgW  = 24;
            imgInfo.NeedBorder = false;
            imgInfo.FontStyle  = FontStyle.Regular;
            imgInfo.FontSize   = 22;
            imgInfo.Brush      = Brushes.White;

            // 显示进度条
            this.ResetProcessBar(allZhTxt.Count);

            //Bitmap cnFontData = new Bitmap(24, 24 * allZhTxt.Count);
            int charIndex = 0;

            foreach (int unicodeChar in allZhTxt)
            {
                imgInfo.NewImg();
                imgInfo.CharTxt  = Encoding.BigEndianUnicode.GetString(new byte[] { (byte)(unicodeChar >> 8 & 0xFF), (byte)(unicodeChar & 0xFF) });
                imgInfo.XPadding = 0;
                imgInfo.YPadding = 0;
                ImgUtil.WriteBlockImg(imgInfo);

                // 保存字符映射表信息
                byte[] byChar    = Encoding.BigEndianUnicode.GetBytes(imgInfo.CharTxt);
                byte[] byCurChar = new byte[4];
                Array.Copy(byChar, 0, byCurChar, 0, byChar.Length);
                //this.SetCharPadding(byCurChar, imgInfo.Bmp);
                imgInfo.Bmp = this.SetCharPadding(byCurChar, imgInfo.Bmp);
                charIndexMap.AddRange(byCurChar);
                //charInfoMap.AddRange(byCurChar);


                //for (int y = 0; y < 24; y++)
                //{
                //    for (int x = 0; x < 24; x++)
                //    {
                //        cnFontData.SetPixel(x, charIndex * 24 + y, imgInfo.Bmp.GetPixel(x, y));
                //    }
                //}


                if (charIndex++ < 200)
                {
                    imgInfo.Bmp.Save(@"E:\Study\MySelfProject\Hanhua\fontTest\CharPng\" + unicodeChar + ".png");
                }

                //charIndex = charPngData.Count;
                //charIndexMap.Add((byte)(charIndex >> 24 & 0xFF));
                //charIndexMap.Add((byte)(charIndex >> 16 & 0xFF));
                //charIndexMap.Add((byte)(charIndex >> 8 & 0xFF));
                //charIndexMap.Add((byte)(charIndex & 0xFF));

                // 保存文字图片信息
                byte[] byCharFont = Util.ImageEncode(imgInfo.Bmp, "IA8");
                //charPngData.AddRange(byCharFont);

                charIndexMap.AddRange(byCharFont);

                // 更新进度条
                this.ProcessBarStep();
            }

            // 隐藏进度条
            this.CloseProcessBar();

            File.WriteAllBytes(@"E:\Study\MySelfProject\Hanhua\fontTest\FontCn_IA8(N64).dat", charIndexMap.ToArray());
            //File.WriteAllBytes(@"E:\Study\MySelfProject\Hanhua\fontTest\FontCn_IA8.dat", Util.ImageEncode(cnFontData, "IA8").ToArray());
            //File.WriteAllBytes(@"E:\Study\MySelfProject\Hanhua\fontTest\FontCnCharInfo.dat", charInfoMap.ToArray());
            //File.WriteAllBytes(@"H:\游戏汉化\fontTest\ZhBufFont_IA8.dat", charIndexMap.ToArray());
        }