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

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

问题描述

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

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?

How to make a ICNS out of this?

我想使用sip,但是sip只占用一个文件,并且可以进行所有缩放:

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张图像并从中取出图像呢?如果饮者不能这样做,还有其他方法吗?

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系统上,它是基本OS的一部分.这不是特殊的安装,例如开发人员工具.您可以使用以下方法进行验证:

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软件包的一部分,也是基本OS的一部分.

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或其他方式以编程方式使Mac OS X ICNS具有10个不同的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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