按键精灵字库文件点阵图显示Java代码

如题:

不知道为什么,按照一行22个点去打印的话,显示的是一个侧着的字,需要倒转一下

public class Test {

    public static void main(String[] args) {
        String s = "01800B0200F40C07181870300300000020C000C303030C0C0C303030C0C0E30303EFFFFDFFFFF0C0C0C303030C0C0C303030C0C0C300030000030";
        //String s = "00C0100301E00C7E3FFFC0C0C00303002C0C00B03006FFFFF80300000C0380307C7FFF83FF800C0C00303003C0C00F03002FFFFF80300000C000030000";
        String bin = hexToBin(s);
        int step = 22;
     // 这段打印代码会显示倒着的字
        //for (int i = 0; i < bin.length(); i+=step) {
        //    System.out.println(bin.substring(i, i+step>bin.length()?bin.length():i+step));
        //}

         for (int i = 0; i < 22; i++) {
             int j = i;
             while(j < bin.length() ){
                 System.out.print(bin.charAt(j>bin.length()-1?bin.length()-1:j));
                 j += step;
             }
             System.out.println();
        }

    }

    public static String hexToBin(String hex){
        String bin = "";
        String binFragment = "";
        int iHex;
        hex = hex.trim();
        hex = hex.replaceFirst("0x","");
        for(int i = 0; i < hex.length(); i++){
            iHex = Integer.parseInt(""+hex.charAt(i),16);
            binFragment = Integer.toBinaryString(iHex);
            while(binFragment.length() < 4){
                binFragment = "0" + binFragment;
            }
            binFragment = binFragment.replaceAll("0", " ");
            bin += binFragment;
            //System.out.print(binFragment);
            //int j = 7;
            //if (i % j == j-1) {
            //    System.out.println();
            //}
        }
        return bin;
    }
}

 

 显示的样子,

 1         11        1
 111        11       1
   11       11        
    1        1        
      11111111111111  
      11111111111111  
            11       
1           11       
111         11       
  11        11       
   1        11       
            11       
       111111111111  
       111111111111  
    1       11       
   11       11       
   1        11       
  11        11       
 11         11       
 11         11       
11   111111111111111 
 1    11111111111111 

 

posted @ 2022-11-23 14:05  MarshWinter  阅读(135)  评论(0编辑  收藏  举报