示例#1
0
        /// <summary>
        /// 写字库图片
        /// </summary>
        /// <param name="imgInfo">图片信息</param>
        /// <param name="txtList">文字信息</param>
        /// <returns>写好文字的图片</returns>
        public static Bitmap WriteFontImg(ImgInfo imgInfo, List <string> txtList)
        {
            // 参数检查
            ImgUtil.ImgInfoCheck(imgInfo);

            // 计算行、列信息
            int xNum         = imgInfo.ImgW / imgInfo.BlockImgW;
            int yNum         = imgInfo.ImgH / imgInfo.BlockImgH;
            int maxCharCount = xNum * yNum;

            for (int i = 0; i < maxCharCount; i++)
            {
                // 设置当前字符
                imgInfo.CharTxt = txtList[i];

                // 计算位置
                imgInfo.PosX = (i % xNum);
                imgInfo.PosY = (i / xNum);

                // 生成当前块图片
                ImgUtil.WriteBlockImg(imgInfo);
            }

            return(imgInfo.Bmp);
        }
示例#2
0
        /// <summary>
        /// 初始化
        /// </summary>
        private void InitPage()
        {
            // 读取字库信息
            this.lstFont.Items.Clear();
            this.fontList = ImgUtil.GetFontList();
            foreach (KeyValuePair <string, string> fontInfo in this.fontList)
            {
                this.lstFont.Items.Add(fontInfo.Value);
            }
            this.lstFont.SelectedIndex = 0;

            // 绑定事件
            this.lstFont.SelectedIndexChanged += new System.EventHandler(this.lstFont_SelectedIndexChanged);

            // 生成Sample图片
            this.CreateSampleImg();
        }
示例#3
0
        /// <summary>
        /// 写整行文字的图片
        /// </summary>
        /// <param name="imgInfo">图片信息</param>
        /// <param name="txtList">文字信息</param>
        /// <returns>写好文字的图片</returns>
        public static Bitmap WriteLineTxtImg(ImgInfo imgInfo, string txt)
        {
            // 参数检查
            ImgUtil.ImgInfoCheck(imgInfo);

            // 拆分字符
            char[] txtList = txt.ToCharArray();

            for (int i = 0; i < txtList.Length; i++)
            {
                // 设置当前字符
                imgInfo.CharTxt = txtList[i].ToString();

                // 计算当前位置
                imgInfo.PosX += imgInfo.BlockImgW;

                // 生成当前块图片
                ImgUtil.WriteBlockImg(imgInfo);
            }

            return(imgInfo.Bmp);
        }
示例#4
0
        /// <summary>
        /// 生成Sample图片
        /// </summary>
        private void CreateSampleImg()
        {
            //this.pnlSample.Height = Convert.ToInt32(this.txtBlockH.Text) + 2;

            // 设置图片参数
            int blockImgW = Convert.ToInt32(this.txtBlockW.Text);
            int blockImgH = Convert.ToInt32(this.txtBlockH.Text);

            this.imgInfo            = new ImgInfo(blockImgW, blockImgH);
            this.imgInfo.BlockImgW  = blockImgW;
            this.imgInfo.BlockImgH  = blockImgH;
            this.imgInfo.XPadding   = Convert.ToInt32(this.txtXPadding.Text);
            this.imgInfo.YPadding   = Convert.ToInt32(this.txtYPadding.Text);
            this.imgInfo.NeedBorder = this.chkNeedBorder.Checked;
            this.imgInfo.FontName   = this.fontList[this.lstFont.SelectedIndex].Key;
            this.imgInfo.FontSize   = Convert.ToInt32(this.txtFontSize.Text);

            // 开始写文字
            // 拆分字符
            char[]  txtList  = this.txtSample.Text.ToCharArray();
            Image[] rowImage = new Image[txtList.Length];
            for (int i = 0; i < txtList.Length; i++)
            {
                this.imgInfo.NewImg();

                // 设置当前字符
                imgInfo.CharTxt = txtList[i].ToString();

                // 生成当前块图片
                ImgUtil.WriteBlockImg(imgInfo);

                rowImage[i] = imgInfo.Bmp;
            }

            this.grdSampleImg.Rows.Clear();
            int addedRow = this.grdSampleImg.Rows.Add(rowImage);
            //this.grdSampleImg.Rows[addedRow].Height = 32;
        }
示例#5
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());
        }
示例#6
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());
        }