Developpement/23DEV1.1/TPS2/TP01/FluxDeCaracteres/Image.java

43 lines
1.1 KiB
Java
Raw Permalink Normal View History

2024-12-09 11:53:11 +01:00
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.io.File;
public class Image
{
public static String remove_quote(String line)
{
return line.substring(1,line.length()-2);
}
public static void main(String[] args)
{
/*if(args.length == 0)
{
System.err.println("Need image path");
System.exit(1);
}*/
try
{
BufferedReader img_file = new BufferedReader(new FileReader("./image.xpm"));
String line = null;
int width, height, number_of_colors, pixel_size;
//Read metaData
while((line= img_file.readLine())!=null)
{
if(line.charAt(0) != '"'){
continue;
}
String[] metadatas = remove_quote(line).split(" ");
width = Integer.parseInt(metadatas[0]);
height = Integer.parseInt(metadatas[1]);
number_of_colors = Integer.parseInt(metadatas[2]);
pixel_size = Integer.parseInt(metadatas[3]);
System.out.println(width+""+height+""+number_of_colors+""+pixel_size);
break;
}
}catch(IOException | NumberFormatException e){
System.err.println(e.getMessage());
System.exit(1);
}
}
}