Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.awt.image.BufferedImage;
- import javax.imageio.ImageIO;
- public class Main {
- static File png;
- static File csv;
- static BufferedImage img= null;
- static int gridWidth = 1;
- static int gridHeight = 1;
- Main(){};
- /**
- * @param args pngname;csvname;RGB as Hex;sign;gridWidth;gridHeight
- */
- public static void main(String[] args) {
- if (args[0].equals("help")){
- System.out.println("A simple Program to convert a png into an csv, which then can be imported into quickfort, which can be used to design a Fortress in Dwarf Fortress" +
- "\n\n" +
- "The Number of Arguments must be 6 or 4:\n" +
- "pngpath: path to the png \n" +
- "csvname: path to the csv that should be generated \n" +
- "RGB_as_6Hex: the colour which should be used to determinate the place of the sign. Must consist of 6 hexnumbers \n" +
- "sign: The letter, or sign which will be used. f.e. d for dig \n" +
- "gridWidth: How many pixels should be jumped horizontally. 1 means every pixel \n" +
- "gridHeight: hom many pixels should be jumped vertically. 1 means every pixel\n" +
- "alpha gets ignored, so care that it has a completely different colour");
- System.exit(0);
- }
- if ((args.length > 6) || (args.length != 4 && args.length != 6))
- {
- System.out.println("Wrong Number of Arguments!\n" +
- "Must be 6:\n" +
- " pngname csvname RGB_as_6Hex sign gridWidth gridHeight\n" +
- "or 4: \n" +
- " pngname csvname RGB_as_6Hex sign \n" +
- " grid is set to 1\n" +
- "write help as argument for help" );
- System.exit(2);
- }
- if (args.length == 6){
- if ((args[4].equals("0")) || (args[5].equals("0"))){
- System.out.println("gridsize isn't allowed to be zero. \n" +
- "write help as argument for help");
- System.exit(3);
- }
- gridWidth = Integer.valueOf(args[4]);
- gridHeight = Integer.valueOf(args[5]);
- }
- if (args[2].length() > 6){
- System.out.println("Colour Bitmap too long, Max 6 HexNumbers \n" +
- "White = FFFFFF\n" +
- "Black = 000000\n" +
- "Red = FF0000\n" +
- "Green = 00FF00\n" +
- "Blue = 0000FF");
- System.exit(2);}
- try{
- png = new File(args[0]);
- if (!png.exists()){
- System.out.println("Error: pngFile doesn't exists");
- System.exit(1);
- }
- csv = new File(args[1]);
- if (!csv.exists()){
- csv.createNewFile();
- };
- //png read
- img = ImageIO.read(png);
- BufferedWriter out =new BufferedWriter( new FileWriter(csv));
- int col = Integer.valueOf(args[2],16) & 0xFFFFFF;
- // String cox = "000000";
- // int col = Integer.valueOf(cox, 16);
- for(int h = 0; h < img.getHeight();h+=gridHeight){
- for(int w = 0; w < img.getWidth();w += gridWidth){
- String s = "";
- // int g = img.getRGB(w, h) ;
- if( (img.getRGB(w, h) & 0x00FFFFFF) == col)
- {
- s =""+args[3];
- }
- out.write(s);
- out.write(';');
- }
- out.write("\n");
- }
- out.close();
- System.out.println("Size:\n" +
- "Heigh:" + (double)img.getHeight()/gridHeight + "\n" +
- "Width:" + (double)img.getWidth()/gridWidth);
- System.out.println("Done...");
- System.exit(0);
- // TODO Auto-generated method stub
- } catch (IOException e) { e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement