icns苹果图标,以及用java进行转换PNG

什么是icns格式文件

icns 是一种专门用于在 macOS 上显示应用程序和文件图标的文件格式。

苹果采用这种格式的原因在于,它支持在一个 icns 文件中存储各种分辨率 (16x16x 至 1024×1024),可以存储多个分辨率的图标,以便在不同的显示器分辨率下呈现最佳图像质量。

此外,icns 格式还允许存储 alpha 通道,这是一种透明度信息,使图标能够呈现圆角、半透明等复杂形状。

因此,icns 格式在苹果操作系统中成为了一种常用的图标文件格式。

 


也可以使用整合包进行更快速的学习和改造


icns转png代码示例

public static void exec(byte[] inputBytes) {
//        File file = new File("D:\\Desktop\\your.icns");
        ByteArrayInputStream inputStream = new ByteArrayInputStream(inputBytes);
        File out = new File("D:\\Desktop\\out.png");

        try {
            ImageInputStream input = ImageIO.createImageInputStream(inputStream);
            ImageReader reader = ImageIO.getImageReadersByFormatName("icns").next();
            reader.setInput(input);

            ImageReadParam param = reader.getDefaultReadParam();

            int numImages = reader.getNumImages(true);
            int maxWidth = 0;
            int maxHeight = 0;
            int maxIndex = 0;

            for (int i = 0; i < numImages; i++) {
                BufferedImage image = reader.read(i, param);
                if (image.getWidth() > maxWidth || image.getHeight() > maxHeight) {
                    maxHeight = image.getHeight();
                    maxWidth = image.getWidth();
                    maxIndex = i;
                }
            }
            BufferedImage max = reader.read(maxIndex, param);

            ImageIO.write(max, "png", out);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


点击返回顶部

左上角红星点个赞吧,么么哒~

文章

什么是乐观锁,看完你就了解了

2024-4-2 10:34:45

文章

MacOS常用快捷键

2024-4-2 10:37:41

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索