2010-09-21 4 views

Répondre

4
+0

Il est ici maintenant: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/icns/IcnsDecoder.java?view = balisage Merci beaucoup. Cela va m'aider à faire un fichier .app sous GNU Linux et Windows: https://sourceforge.net/p/tuer/tickets/9/#c109 – gouessej

2

Vous devez convertir ICNS à un autre type d'image d'abord, et après charge cette image vous pouvez le supprimer. Voici comment convertir PNG à ICNS, vous avez juste besoin de faire dans le sens inverse:

public static void Png(File png, File icns) throws IOException{ 
    ImageIcon image = new ImageIcon(ImageIO.read(png)); 
    ImageIconAs(image, icns); 
} 

public static void ImageIconAs(ImageIcon ii, File icns) throws IOException{IconAs((Icon)ii,icns);} 

public static void IconAs(Icon icon, File icns) throws IOException{ 
     if (icon != null) { 
       BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); 
       Graphics2D g = bi.createGraphics(); 
       icon.paintIcon(new Canvas(), g, 0, 0); 
       g.dispose(); 
       File outputfile = new File("temp000.png"); 
       ImageIO.write(bi, "png", outputfile); 
       execTerminal(new String[]{ "sips", "-s", "format", "tiff", 
         "temp000.png","--out", "temp000.tiff" }); 
       File apaga2 = new File("temp000.png"); 
       apaga2.delete(); 
       execTerminal(new String[]{ "tiff2icns", "-noLarge", 
         "temp000.tiff", icns.getAbsolutePath()}); 
       File apaga = new File("temp000.tiff"); 
       apaga.delete(); 
     } 
    } 

static void execTerminal(String[] cmd){ 
     int exitCode = 0; 
     try { 
      exitCode = Runtime.getRuntime().exec(cmd).waitFor(); 
     } 
     catch (InterruptedException e) {e.printStackTrace();} 
     catch (IOException e) { 
      if (exitCode != 0) System.out.println("ln signaled an error with exit code " + exitCode); 
     } 
    } 

Vous avez juste besoin de l'utiliser pour appeler l'action:

Png (png_file, icns_file);

Questions connexes