ASCII点阵 16x8 与24x16 Java

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值