/// <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); }
/// <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); }