Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用Java读取OS X*.icns文件_Java_Macos_Graphics - Fatal编程技术网

如何用Java读取OS X*.icns文件

如何用Java读取OS X*.icns文件,java,macos,graphics,Java,Macos,Graphics,我想将OS X中的*.icns文件读入BuffereImage。帮助尝试以下操作: 这实际上来自:您需要先将ICN转换为另一种图像类型,加载此图像后,您可以将其删除。这是如何将PNG转换为ICN的,因此您只需要以相反的方式进行: public static void Png(File png, File icns) throws IOException{ ImageIcon image = new ImageIcon(ImageIO.read(png)); ImageIconAs

我想将OS X中的*.icns文件读入BuffereImage。帮助

尝试以下操作:


这实际上来自:

您需要先将ICN转换为另一种图像类型,加载此图像后,您可以将其删除。这是如何将PNG转换为ICN的,因此您只需要以相反的方式进行:

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);
        }
    }
您只需使用此命令调用操作:

Png(Png_文件、icns_文件)

你可以自己做。它使用以下图标格式:

  • *.ico-Windows图标
  • *.icl-Windows图标库
  • *.icns-麦金塔图标
现在就在这里:非常感谢。它将帮助我在GNU Linux和Windows下创建一个.app文件: