1
字库下载链接:https://download.csdn.net/download/llapton/12910449
.ASCII与汉字寻址公式不同,注意区分,寻址公式如下图
2
.16x8 ASCII点阵显示,注意这里使用的字库为"ASC16",注意寻址公式为 offset = ascii * 16
package tools;
import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public class AsciiPoint {
public static void main(String[] args) throws IOException {
String str = "B";
char[] key = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
int size_step = 8;
//16x8的ASCII点阵
byte[] cbuf = new byte[16];
byte[] bytes = str.getBytes("ASCII");
System.out.println(Arrays.toString(bytes));
//byte转int
int ascii = bytes[0] & 0xff;
//计算偏移量
int offset = ascii * 16;
//读取点阵字库文件,需要按需修改为你电脑上实际字库的绝对地址
ClassPathResource classPathResource = new ClassPathResource("ASC16");
InputStream inputStream = classPathResource.getInputStream();
//跳过offset个字节,读取汉字占用的16个字节
inputStream.skip(offset);
inputStream.read(cbuf);
//按行解析
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 8; j++) {
int index = i * 8 + j;
int flag = cbuf[index / size_step] & key[index % size_step];
System.out.print(flag > 0 ? "●" : "○");
}
System.out.println();
}
}
}
16x8效果:
**
3
24x16 ASCII点阵显示,注意这里使用的字库为"ASC24",注意寻址公式为 offset = (ascii-32) * 16
package tools;
import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public class AsciiPoint24 {
public static void main(String[] args) throws IOException {
String str = "t";
char[] key = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
int size_step = 8;
//24x16的ASCII点阵
byte[] cbuf = new byte[48];
byte[] bytes = str.getBytes("ASCII");
System.out.println(Arrays.toString(bytes));
//byte转int
int ascii = bytes[0] & 0xff;
//计算偏移量
int offset = (ascii-32) * 48;
//读取点阵字库文件,需要按需修改为你电脑上实际字库的绝对地址
ClassPathResource classPathResource = new ClassPathResource("ASC24");
InputStream inputStream = classPathResource.getInputStream();
//跳过offset个字节,读取汉字占用的16个字节
inputStream.skip(offset);
inputStream.read(cbuf);
//按行解析
for (int i = 0; i < 24; i++) {
for (int j = 0; j < 16; j++) {
int index = i * 16 + j;
int flag = cbuf[index / size_step] & key[index % size_step];
System.out.print(flag > 0 ? "●" : "○");
}
System.out.println();
}
}
}
24x16 效果如下:
字库下载链接:https://download.csdn.net/download/llapton/12910449