packageorg.my.util;importjava.io.BufferedReader;importjava.io.File;importjava.io.FileNotFoundException;importjava.io.FileReader;importjava.io.IOException;public classConfig {private static String filePath = "C:/Users/issuser/Desktop/a-z";public static int[][] getBinArr(String c){int[][] arr = new int[16][8];
File f= new File(filePath+"/"+c+".txt");try{
BufferedReader reader= new BufferedReader(newFileReader(f));for(int i=0;i<16;i++){
String s=reader.readLine();for(int j=0;j<8;j++){if('1'==s.charAt(j)){
arr[i][j]= 1;
}else{
arr[i][j]= 0;
}
}
}
reader.close();
}catch(FileNotFoundException e) {//TODO Auto-generated catch block
e.printStackTrace();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}returnarr;
}public static int[][] reorg(int[][] a,int[][] b){int al = a[0].length;int bl = b[0].length;int[][] r = new int[a.length][al+bl];for(int i=0;i
r[i][j]=a[i][j];
}
}for(int i=0;i
r[i][j+al]=b[i][j];
}
}returnr;
}
}packageorg.my.main;importjava.awt.image.BufferedImage;importjava.io.File;importjava.io.FileOutputStream;importjava.io.IOException;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importjavax.imageio.ImageIO;importorg.my.util.Config;public classTestABC {private static Map map = new HashMap();public static void main(String[] args) throwsIOException {
initMap();
String str= "The first step is as good as half over.***pYou never know your luck.***pSow nothing, reap nothing.***pThe wealth of the mind is the only wealth.";
List list = new ArrayList();
String[] strarr= str.split("\\*\\*\\*p");for(String strs : strarr){
list.add(toArr(strs));
}//int[][] tmp = toArr(str);
BufferedImage bi= ImageIO.read(new File("C:/Users/issuser/Desktop/desktop.jpg"));
writeLine(bi,560,360,list);
ImageIO.write(bi,"jpg", new FileOutputStream(new File("C:/Users/issuser/Desktop/desktop-bak.jpg")));
}private static void out(int[][] tmp){for(int i=0;i
System.out.print(tmp[i][j]);
}
System.out.println();
}
}private static voidinitMap(){
String[] cs= {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","space","comma","point"};for(int i=0;i
map.put(cs[i], Config.getBinArr(cs[i]));
}
}private static int[][] toArr(String str){int[][] tmp = Config.getBinArr(str.charAt(0)+"");for(int i=1;i
tmp= Config.reorg(tmp, map.get("space"));
}else if(str.charAt(i)==','){
tmp= Config.reorg(tmp, map.get("comma"));
}else if(str.charAt(i)=='.'){
tmp= Config.reorg(tmp, map.get("point"));
}else{
tmp= Config.reorg(tmp, map.get(""+str.charAt(i)));
}
}returntmp;
}private static void writeLine(BufferedImage bi,int x,int y,Listlist){for(int[][] data : list){
insert(bi,x,y,data);
y+=16;
}
}private static void insert(BufferedImage bi,int x,int y,int[][] data){for(int i=0;i
bi.setRGB(x+j, y+i, 0x00ffffff);
}
}
}
}
}
字符文件地址
https://files.cnblogs.com/files/cfdx/a-z.rar