java图片加注_java 图片添加水印

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值