public class ImageForString { private final static char[] asc = { '*', '.', ' ', ' ' }; public static StringBuilder imageToAscii(BufferedImage image)throws IOException{
StringBuilder strb=new StringBuilder(); int width=image.getWidth(); int height=image.getHeight(); for(int i=0;i<height;i++){ for(int j=0;j<width;j++){ int rgb=image.getRGB(j,i); int R=(rgb&0xff0000)>>16; int G=(rgb&0x00ff00)>>8; int B=rgb&0x0000ff; int gray=R+G+B; int index=gray/255;
strb.append(asc[index]);
}
strb.append("\n");
}