Created
May 30, 2019 12:02
-
-
Save LeRoiDesKiwis/04eed3bcb90c32962d2fc4a56832bd45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ascii art