如何使用 sip 或其他方式以编程方式制作具有 10 个不同图像的 Mac OS X ICNS [英] How to programmatically make Mac OS X ICNS with 10 different images using sips or other

查看:16
本文介绍了如何使用 sip 或其他方式以编程方式制作具有 10 个不同图像的 Mac OS X ICNS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我需要拥有.我需要以编程方式实现这一点.

My issue is that i need have. I need to achieve this programmatically.

因此,对于 mac os x,应用程序图标应具有以下大小:

So for mac os x an application icon should have these sizes:

我有 10 张图片.每一个我都在右角放了一个徽章,这个徽章的位置和位置没有缩放.所以我有 10 个不同的图像.

I have 10 images. Each one i placed a badge in the right corner, the placement and position of this badge does not scale. So i 10 different images.

如何制作 ICNS?

我想使用 sips,但是 sips 只需要一个文件,它可以完成所有的缩放:http://cccache.bingj+aspicq=n3PZcWn6bEPxt4O96PPLd6nugtVq5jDzsips+argument+list&d=5035141870911884&mkt=en-US&setlang=en-US&w=n3PZcWn6bEPxt4O96PPLd6nugtVq5jDz

I thought to use sips, however sips only takes one file and it does all the scalings: http://cc.bingj.com/cache.aspx?q=mac+icns+sips+argument+list&d=5035141870911884&mkt=en-US&setlang=en-US&w=n3PZcWn6bEPxt4O96PPLd6nugtVq5jDz

有没有办法让 /usr/bin/sips 拍摄我的 10 张图片并用它制作 icns?如果sips不能做到,还有其他方法吗?

Is there a way to make /usr/bin/sips take my 10 images and make a icns out of it? If sips cant do it is there any other way?

推荐答案

如果你想使用 iconutil,你可以这样做.至少在我的 10.9.5 系统上,它是基本操作系统的一部分.它不是特殊的安装,如开发人员工具.您可以使用以下方法验证:

If you want to use iconutil, you can do that. At least on my 10.9.5 system, it's part of the base OS. It's not a special install, like developer tools. You can verify that using:

pkgutil --file-info /usr/bin/iconutil

这里,输出:

volume: /
path: /usr/bin/iconutil

pkgid: com.apple.pkg.BSD
pkg-version: 10.9.0.1.1.1306847324
install-time: 1402788942
uid: 0
gid: 0
mode: 755

重要的部分是 pkgid.它是 BSD 包的一部分,后者是基本操作系统的一部分.

The important part is the pkgid. It's part of the BSD package, which is part of the base OS.

也就是说,编写一些代码来做到这一点并不难.

That said, it's not hard to write a bit of code to do this.

您可以使用 CGDestination API.使用 CGImageDestinationCreateWithURL() 创建目的地.对于type,传递kUTTypeAppleICNS.

You can use the CGDestination API. Create a destination using CGImageDestinationCreateWithURL(). For the type, pass kUTTypeAppleICNS.

鉴于您想从单个文件添加图像,使用 CGImageSourceCreateWithURL() 为每个文件创建一个 CGImageSource 可能是最简单的.然后,您可以使用 CGImageDestinationAddImageFromSource() 直接将图像从源添加到目标.将每个源的图像添加到目标后,不要忘记 CFRelease().

Given that you want to add images from individual files, it's probably easiest to create a CGImageSource for each using CGImageSourceCreateWithURL(). Then, you can directly add an image from the source to the destination using CGImageDestinationAddImageFromSource(). Don't forget to CFRelease() each source after you've added its image to the destination.

然后,调用 CGImageDestinationFinalize() 让目标将图像写出到 URL.然后,CFRelease() 目的地.

Then, call CGImageDestinationFinalize() to have the destination write out the image to the URL. Then, CFRelease() the destination.

如果每个源图像都设置了正确的 DPI,则会将其完整复制到目标位置.如果源图像没有设置正确的 DPI,您可以通过将属性字典传递给 CGImageDestinationAddImageFromSource() 来覆盖它.包括键 kCGImagePropertyDPIHeightkCGImagePropertyDPIWidth,每个键都具有一个具有所需 DPI 的 CFNumber 对象的对应值.对于正常分辨率的图标,请使用 72 DPI.对于高分辨率 (@2x) 图标,请使用 144 DPI.

If each of the source images has the proper DPI set, this will be copied over intact to the destination. If the source images don't have the proper DPI set, you can override it by passing a dictionary of properties to CGImageDestinationAddImageFromSource(). Include the keys kCGImagePropertyDPIHeight and kCGImagePropertyDPIWidth, each with a corresponding value of a CFNumber object with the desired DPI. For a normal-resolution icon, use 72 DPI. For a high-resolution (@2x) icon, use 144 DPI.

创建 ICNS 文件也可以使用旧的 IconFamily API 来完成,但有点麻烦.此外,它不支持高分辨率图标.

Creating ICNS files can also be done using the old IconFamily API, but it's a bit hairy. Also, it doesn't support high-resolution icons.

首先,您为图标系列创建一个句柄(指针到指针到可调整大小的缓冲区):

First, you create a handle (pointer-to-pointer-to-resizable-buffer) for the icon family:

IconFamilyHandle iconFamily = (IconFamilyHandle)NewHandle(0);

然后,对于每个图像大小(16、32、128、256 和 512),您为图像数据的原始位图创建一个句柄.位图应该是每像素 32 位,每组件 8 位,ARGB 非预乘数据,没有填充.

Then, for each image size (16, 32, 128, 256, and 512), you create a handle for a raw bitmap of the image data. The bitmap should be 32 bits per pixel, 8 bits per component, ARGB non-premultiplied data with no padding.

int size = /* 16, 32, 128, 256, or 512 */;
Handle handle = NewHandle(size * size * 4);
// fill handle with image data; buffer pointer is *handle

然后,您可以通过如下调用将该句柄添加到图标系列中:

Then, you add that handle to the icon family with a call like:

SetIconFamilyData(iconFamily, kIconServices16PixelDataARGB, handle);

对于其他尺寸,将 kIconServices16PixelDataARGB 中的16"替换为适当的值.

For the other sizes, replace the "16" in kIconServices16PixelDataARGB with the appropriate value.

然后,您将图标系列句柄的数据写入文件.通过简单地取消引用句柄(即 *iconFamily)获得指向数据的指针.它的大小是通过调用GetHandleSize((Handle)iconFamily)获得的.

Then, you write the icon family handle's data out to file. A pointer to the data is obtained by simply dereferencing the handle (i.e. *iconFamily). Its size is obtained by calling GetHandleSize((Handle)iconFamily).

通过调用 DisposeHandle() 处理您在此过程中创建的任何句柄.

Dispose of any handles you created along the way by calling DisposeHandle().

这篇关于如何使用 sip 或其他方式以编程方式制作具有 10 个不同图像的 Mac OS X ICNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆