首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用Java读取OS X *.icns文件

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

Stack Overflow用户
提问于 2010-09-21 13:59:43
回答 3查看 1.3K关注 0票数 3

我想将OS X中的*.icns文件读取到BufferedImage中。帮助

EN

回答 3

Stack Overflow用户

发布于 2011-08-07 21:25:44

试试这个:http://code.google.com/p/appengine-awt/source/browse/trunk/apache-sanselan/src/main/java/org/apache/sanselan/formats/icns/IcnsDecoder.java?spec=svn8&r=8

它实际上来自:http://incubator.apache.org/sanselan/site/index.html

票数 4
EN

Stack Overflow用户

发布于 2012-05-30 04:04:17

您需要先将ICNS转换为另一种镜像类型,加载此镜像后,您可以将其删除。这就是如何将PNG转换为in,所以您只需要以相反的方式进行操作:

代码语言:javascript
复制
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_file,icns_file);

票数 2
EN

Stack Overflow用户

发布于 2020-05-31 17:56:46

你可以使用IconManager。它使用以下图标格式:

  • *.ico - Windows Icon
  • *.icl - Windows图标Library
  • *.icns - Macintosh图标
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3757677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档