Skip to content

Instantly share code, notes, and snippets.

@LeRoiDesKiwis
Created May 30, 2019 12:02
Show Gist options
  • Save LeRoiDesKiwis/04eed3bcb90c32962d2fc4a56832bd45 to your computer and use it in GitHub Desktop.
Save LeRoiDesKiwis/04eed3bcb90c32962d2fc4a56832bd45 to your computer and use it in GitHub Desktop.
package fr.leroideskiwis.imageToText;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Main {
private Scanner scanner = new Scanner(System.in);
private Main() throws IOException {
File file = readFile("Path : ", true);
BufferedImage image = ImageIO.read(file);
StringBuilder builder = new StringBuilder();
for(int y = 0; y < image.getHeight(); y++){
for(int x = 0; x < image.getWidth(); x++){
if(image.getRGB(x,y) > new Color(128, 128, 128).getRGB())
builder.append(".");
else
builder.append("x");
builder.append(" ");
}
builder.append("\n");
}
System.out.println(builder.toString());
}
public static void main(String[] args) throws IOException {
new Main();
}
public String readString(String string){
System.out.print(string);
String readed = scanner.nextLine();
System.out.println();
return readed;
}
public File readFile(String string, boolean needExists){
File file;
do{
file = new File(readString(string));
}while(needExists != file.exists());
return file;
}
}
@LeRoiDesKiwis
Copy link
Author

LeRoiDesKiwis commented May 30, 2019

L'original :
exemple

Le texte :
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x . . . . . x x x x x x x . . . . . x x x x x x x x x x x x x x
x x x x x x x x x x x . . x x x . . . . . . x x . . . . . . x x . . x x x x x x x x x x x
x x x x x x x x x x . . . . . x x x x x x x x x x x x x x x x . . . . x x x x x x x x x x
x x x x x x x x x . . . . . x x x x x x x x x x x x x x x x x . . . . . x x x x x x x x x
x x x x x x x x x x . . x x x x x x . . . . . . . . . x x x x x x . . x x x x x x x x x x
x x x x x x x x x x x x x x x . . . . . x . . . x . . . . . x x x x x x x x x x x x x x x
x x x x x . . . . x x x x x . . . . . x x . . . x x . . . . . x x x x x . . . . x x x x x
x x x x . . . . . . x x x . . . . x x x x . . . x x x x . . . . x x x . . . . . . x x x x
x x x . . . . . . . x x . . . . . . . x x . . . x x . . . . . . . x x . . . . . . . x x x
x x . . . x x x x x x x . . . . . . . x x . . . x x . . . . . . . x x x x x x x . . . x x
x x . . . . . . . x x x . . . . . . x x x . . . x x x . . . . . . x x x . . . . . . . x x
x x . . . . . . . . x x . . . x . . . . . . . . . . . . . x . . . x x . . . . . . . . x x
x x x x . . . . . . x x . . . . x x x x x x x x x x x x x . . . . x x . . . . . . x x x x
x x x x x . . . . . x x x . . . . x . . . . . . . . . x . . . . x x x . . . . . x x x x x
x x x x x x . . . . . x x . . . . . x . x . . . x . x . . . . . x x . . . . . x x x x x x
x x x x x x x x x x x x x x . . . . . x x x x x x x . . . . . x x x x x x x x x x x x x x
x x x x x x x x x x x . x x x . . . . . . . . . . . . . . . x x x . x x x x x x x x x x x
x x x x x x x x x . . . x x x x . . . . . . . . . . . . . x x x x . . . x x x x x x x x x
x x x x x x x x . . . . x x x x x x . . . . . . . . . x x x x x x . . . . x x x x x x x x
x x x x x x x . . . . x . . x x x x x x x x x x x x x x x x x . . x . . . . x x x x x x x
x x x x x x x . . . x . . . . . . x x x x x x x x x x x . . . . . . x . . . x x x x x x x
x x x x x x x . . . x . . . . . . . . . . . x . . . . . . . . . . . x . . . x x x x x x x
x x x x x x x . . . . . . . . . . . . x x x x x x x x . . . . . . . . . . . x x x x x x x
x x x x x x x x x . . . . . . x x x x x x x x x x x x x x x . . . . . . x x x x x x x x x
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x x . . x x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x . . . . x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x . . . . x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x . . . . x x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x . . . x x x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x . . . x x x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x . . . x x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x . . . . x x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x x . . . . x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x x x . . . x x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x x x x . . . x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x x x x . . . x x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x x x . . . . . x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x . x x x . . . . . . x x . x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x . x x . . . . . . . x x . x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x . x x . . . . . x x . x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x . x x x x x x x . x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x . . . . . . . x x x x x x x x x x x x x x x x x x x
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x

En plus nette :
exemple2

@maxenceeee
Copy link

Whaaaaaaaaaaaou

@Redstonneur1256
Copy link

Ascii art

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment