# Dot Matrix Generator **Repository Path**: walkline/Dot-Matrix-Generator ## Basic Information - **Project Name**: Dot Matrix Generator - **Description**: 用于提取字模的软件 - **Primary Language**: C# - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 2 - **Created**: 2019-07-08 - **Last Updated**: 2023-10-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Dot Matrix Generator ## 项目简介 ![](https://gitee.com/walkline/Dot-Matrix-Generator/raw/master/images/preview.png) 本项目是属于 [Internet Radio Player and IP Broadcast Receiver](https://gitee.com/walkline/Internet-Radio-Player-and-IP-Broadcast-Receiver) 的辅助工具,用于提取中英文字体的字模,并生成适用于 Python 的列表 ## 提取字模原理 1. 新建一个 `Bitmap`,尺寸根据最终需求设定 2. 新建一个 `Font`,设置它的字体、字号、样式等 3. 使用 `Graphics` 对象加载 `Bitmap`,再将需要的文字使用 `Font` 画到 `Bitmap` 上 4. 新建一个二维数组,用于保存 `Bitmap` 中的数据 5. 提取 `Bitmap` 的每一个像素,根据亮度值确定这个像素是否有内容,并以 0 或 1 保存到数组中 ![](https://gitee.com/walkline/Dot-Matrix-Generator/raw/master/images/bitmap.png) 6. 根据数组内容,每 8 位一组作为二进制数转换为十六进制,用于压缩空间 7. 最后根据 Python 所需格式输出字模列表 ```python # [我], size: (16 * 16) 0xe68891: [0x04, 0x40, 0x0E, 0x50, 0x78, 0x48, 0x08, 0x48, 0x08, 0x40, 0xFF, 0xFE, 0x08, 0x40, 0x08, 0x44, 0x0A, 0x44, 0x0C, 0x48, 0x18, 0x30, 0x68, 0x22, 0x08, 0x52, 0x08, 0x8A, 0x2B, 0x06, 0x10, 0x02] ``` ## 如何测试提取的字模 找到并保存 [test/hanzi.py](https://gitee.com/walkline/Dot-Matrix-Generator/raw/master/test/hanzi.py) 文件,使用如下命令即可看到输出效果 ```python python hanzi.py ``` 如果要测试你自己生成的字模,则需要指定 py 文件中 `show()` 函数的参数,例如你生成了如下的字模数据 ```python # [你], size: (21 * 21) 0xe4bda0: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x20, 0x00, 0x04, 0x60, 0x00, 0x04, 0x40, 0x00, 0x0C, 0xFF, 0x18, 0x08, 0x80, 0x08, 0x19, 0x88, 0x08, 0x19, 0x08, 0x10, 0x38, 0x08, 0x00, 0x28, 0x49, 0x00, 0x08, 0xC9, 0x10, 0x08, 0x88, 0x10, 0x08, 0x88, 0x18, 0x09, 0x08, 0x08, 0x09, 0x08, 0x0C, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x08, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] ``` `size` 后边的数字代表字模的大小,也就是宽和高,那么测试代码为 ```python show("你", width=21, height=21) ``` ![](https://gitee.com/walkline/Dot-Matrix-Generator/raw/master/images/you.png) ## 快捷键 可以使用鼠标操作所有设置,还可以使用快捷键 * `Esc`: 快速定位到文字输入框 * `Ctrl + F`: 使 `字体列表` 获得焦点,然后使用键盘 `↑`、`↓` 选择不同字体 * `Ctrl + B`: 字体加粗切换 * `Ctrl + I`: 字体斜体切换 * `Ctrl + S`: 使 `字号列表` 获得焦点,然后使用键盘 `↑`、`↓` 选择不同字号 * `Ctrl + 加号`: 增加外框大小 * `Ctrl + 减号`: 减少外框大小 * `Ctrl + PgUp`: 增加预览图大小 * `Ctrl + pgDn`: 减少预览图大小 * `Ctrl + 方向键`: 调整预览图文字相对位置