Created
May 13, 2019 17:15
-
-
Save LeRoiDesKiwis/6fc834bc5a2704bd96e5dedd0d3e009b 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.imagedecutting; | |
import javax.imageio.ImageIO; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Scanner; | |
public class Main { | |
private Scanner scanner = new Scanner(System.in); | |
private Main() throws IOException { | |
File directory; | |
do { | |
directory = new File(readString("Chemin du dossier : ")); | |
}while(!directory.exists() && !directory.isDirectory()); | |
int sizeX = readInt("Taille des fichiers à l'horizontale : "); | |
int sizeY = readInt("Taille des fichiers à la verticale : "); | |
int imageX = readInt("Nombre d'images à l'horizontale : "); | |
int imageY = readInt("Nombre d'images à la verticale : "); | |
BufferedImage finalImage = null; | |
for(int x = 0; x < imageX; x++){ | |
for(int y = 0; y < imageY; y++) { | |
try { | |
int index = x*imageX+y; | |
int maxIndex = imageX*imageX+imageY; | |
File file = directory.listFiles()[x*imageX+y]; | |
int cursorX = x*sizeX; | |
int cursorY = y*sizeY; | |
BufferedImage image = ImageIO.read(file); | |
if (finalImage == null) finalImage = new BufferedImage(sizeX * imageX, sizeY * imageY, image.getType()); | |
for(int x1 = 0; x1 < sizeX; x1++){ | |
for(int y1 = 0; y1 < sizeY; y1++){ | |
finalImage.setRGB(cursorX+x1, cursorY+y1, image.getRGB(x1,y1)); | |
} | |
} | |
System.out.println("Création "+index+"/"+maxIndex+" ("+getPourc(index, maxIndex)+")"); | |
} catch (Exception exception) { | |
} | |
} | |
} | |
finalImage.flush(); | |
ImageIO.write(finalImage, "png", generateFile(directory.getAbsolutePath()+"/final", ".png")); | |
} | |
private float getPourc(float i, float i1){ | |
return (i/i1)*100; | |
} | |
private File generateFile(String path, String extension){ | |
File file = new File(path+extension); | |
for(int i = 0; file.exists(); i++){ | |
file = new File(path+i+extension); | |
} | |
return file; | |
} | |
private int readInt(String s) { | |
String str; | |
do { | |
str = readString(s); | |
}while(!isNumber(str)); | |
return Integer.parseInt(str); | |
} | |
private boolean isNumber(String s){ | |
try{ | |
Integer.parseInt(s); | |
return true; | |
}catch(Exception ex){ | |
return false; | |
} | |
} | |
public static void main(String[] args) throws IOException { | |
new Main(); | |
} | |
private String readString(String string){ | |
System.out.print(string); | |
String readed = scanner.nextLine(); | |
System.out.println(); | |
return readed; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Avec les textures de minecraft ça donne ça :