如何使用obj-c AppScript将图稿添加到iTunes轨道?

时间:2010-03-10 01:15:25

标签: cocoa itunes nsimage appscript

aTrack是一个ITReference *对象,value是一个NSImage *对象,通过URL初始化为jpeg。

[[[[[aTrack artworks] data_] set] to:value] send];

我在GDB中收到以下消息:

2010-03-09 16:59:42.860 Sandbox[2260:a0f] Can't pack object of class NSImage (unsupported type): <NSImage 0x10054a440 Size={0, 0} Reps=(

然后我尝试了以下代码:

NSData *imageData = [[NSData alloc] initWithData:[value TIFFRepresentation]];
[[[[[aTrack artworks] data_] set] to:imageData] send];

并改为收到此消息

2010-03-09 16:46:09.341 Sandbox[2193:a0f] Can't pack object of class NSConcreteData (unsupported type): <4d4d002a 00000000>

在AppScript文档中,它说“艺术品”项目的“数据”属性是PICTPicture图像。

如何将NSImage转换为PICT?我使用AppScript都错了吗?

1 个答案:

答案 0 :(得分:0)

Appscript没有桥接NSImage,部分原因是因为NSImage是AppKit和appscript只链接到基金会;部分是因为Apple事件使用的这个领域并没有很好地规定。从理论上讲,与图像相关的AEDescs应该包含一个标准的位图数据块,但ISTR在处理iTunes艺术品时会遇到各种麻烦的PICT标题。这太乱了。

NSData没有桥接,因为在没有有意义的描述符类型的情况下将数据打包到AEDesc中是非常没有意义的。如果要打包NSData实例,请使用+[NSAppleEventDescriptor descriptorWithDescriptorType:data:]

另请查看artwork类的raw data属性。这是后来添加的,可能包含更合理的图像数据。

哦,看看EyeTunes框架;它不像使用AppleScript / appscript那样灵活或高效,但我认为它包含用于将NSImage桥接到AEDescs的代码。