/**
* 十六进制转成图片
*
*/
public static boolean saveToImgFile(String src,String output){
if(src==null||src.length()==0){
return false;
}
try{
FileOutputStream out = new FileOutputStream(new File(output));
byte[] bytes = src.getBytes();
for(int i=0;i<bytes.length;i+=2){
out.write(charToInt(bytes[i])*16+charToInt(bytes[i+1]));
}
out.close();
return true;
}catch(Exception e){
e.printStackTrace();
return false;
}
}
private static int charToInt(byte ch){
int val = 0;
if(ch>=0x30&&ch<=0x39){
val=ch-0x30;
}else if(ch>=0x41&&ch<=0x46){
val=ch-0x41+10;
}
return val;
}
使用
main:{
saveToImgFile(hexStr,imgpath)
}