/// <summary> /// 取得当前字符的图片 /// </summary> /// <param name="comImg"></param> /// <param name="secondImg"></param> /// <param name="charInfo"></param> /// <returns></returns> private Bitmap GetCellImage(Bitmap comImg, Bitmap secondImg, Bio0CharInfo charInfo) { Bitmap cellImg = new Bitmap(charInfo.Width, charInfo.Height, PixelFormat.Format32bppArgb); Bitmap fontImg = charInfo.IsUseSecondImg ? secondImg : comImg; if (charInfo.Y > fontImg.Height || charInfo.X > fontImg.Width || charInfo.Y + charInfo.Height > fontImg.Height || charInfo.X + charInfo.Width > fontImg.Width) { return(cellImg); } for (int y = charInfo.Y; y < charInfo.Y + charInfo.Height; y++) { for (int x = charInfo.X; x < charInfo.X + charInfo.Width; x++) { cellImg.SetPixel(x - charInfo.X, y - charInfo.Y, fontImg.GetPixel(x, y)); } } return(cellImg); }
/// <summary> /// 显示字库信息 /// </summary> private void ReadFontFile(string fontFile) { FileStream fs = null; try { // 将文件中的数据,读取到byData中 fs = new FileStream(fontFile, FileMode.Open); byte[] byData = new byte[fs.Length]; fs.Read(byData, 0, byData.Length); fs.Close(); fs = null; // 判断是否正确 if (byData[0x03] != 0x2C || byData[0x07] != 0x0C || byData[0x09] != 0x60) { MessageBox.Show("不是正确生化危机0字库设置文件!"); return; } // 读取当前字库图片 string picNum = fontFile.Substring(fontFile.IndexOf(".bin") - 2, 2); Bitmap img = new Bitmap(@"..\Bio0Edit\bio0Font_" + picNum + ".bmp"); // 取得当前字库信息 int[] picPos = new int[] { 0x2C, 0x03EC, 0x0DEC, 0x17EC, 0x21EC, 0x2BEC, 0x35EC, 0x3FEC, 0x49EC }; List <KeyValuePair <int, int> > charList = new List <KeyValuePair <int, int> >(); List <Bio0CharInfo> charInfoList = new List <Bio0CharInfo>(); int charIndex = 0; for (int i = 0; i < picPos.Length; i++) { // 取得当前页的字库信息 byte[] fontPage; if (i == 0) { fontPage = new byte[0x60 * 10]; } else { fontPage = new byte[256 * 10]; } Array.Copy(byData, picPos[i], fontPage, 0, fontPage.Length); for (int j = 0; j < fontPage.Length;) { // 每10个字节标识一个字符信息 byte[] temp = new byte[10]; Array.Copy(fontPage, j, temp, 0, temp.Length); // 设置当前字符信息 Bio0CharInfo charInfo = new Bio0CharInfo(); charInfo.ByCharInfo = temp; charInfo.CharPage = i == 0 ? 0 : 0x60 + (i - 1); charInfo.X = Util.GetOffset(temp, 2, 3); charInfo.Y = Util.GetOffset(temp, 4, 5); charInfo.Width = Util.GetOffset(temp, 6, 7); charInfo.Height = Util.GetOffset(temp, 8, 9); charInfo.IsUseSecondImg = Util.GetOffset(temp, 0, 1) > 0; charInfoList.Add(charInfo); charList.Add(new KeyValuePair <int, int>(charInfo.Y / 0x1C, charInfo.X / 0x1C)); j += 10; charIndex++; } } // 添加字库图片到Grid List <Bio0CharInfo> aaa = charInfoList.Where(p => p.IsUseSecondImg).ToList(); this.SetFontCharToGrid(charInfoList, img); } catch (Exception me) { MessageBox.Show(me.Message + "\n" + me.StackTrace); return; } finally { if (fs != null) { fs.Close(); } } }