package org.my.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Config {
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(new FileReader(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();
}
return arr;
}
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<a.length;i++){
for(int j=0;j<a[i].length;j++){
r[i][j]=a[i][j];
}
}
for(int i=0;i<b.length;i++){
for(int j=0;j<b[i].length;j++){
r[i][j+al]=b[i][j];
}
}
return r;
}
}
package org.my.main;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.my.util.Config;
public class TestABC {
private static Map<String,int[][]> map = new HashMap<String,int[][]>();
public static void main(String[] args) throws IOException {
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<int[][]> list = new ArrayList<int[][]>();
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<tmp.length;i++){
for(int j=0;j<tmp[i].length;j++){
System.out.print(tmp[i][j]);
}
System.out.println();
}
}
private static void initMap(){
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<cs.length;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<str.length();i++){
if(str.charAt(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)));
}
}
return tmp;
}
private static void writeLine(BufferedImage bi,int x,int y,List<int[][]> list){
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<data.length;i++){
for(int j=0;j<data[i].length;j++){
if(data[i][j]==1){
bi.setRGB(x+j, y+i, 0x00ffffff);
}
}
}
}
}
字符文件地址
https://files.cnblogs.com/files/cfdx/a-z.rar