如何使用 obj-c AppScript 将图稿添加到 iTunes 曲目?
aTrack 是一个 ITReference* 对象,值是一个 NSImage* 对象,通过 jpeg 的 URL 初始化。
[[[[[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 文档中,它说“artwork”项的“data”属性是 PICTPicture 图像。
如何将 NSImage 转换为 PICT?我使用 AppScript 是否完全错误?
aTrack is an ITReference* object, value is an NSImage* object, initialized via a URL to a jpeg.
[[[[[aTrack artworks] data_] set] to:value] send];
I get the following message in 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=(
I then tried the following code:
NSData *imageData = [[NSData alloc] initWithData:[value TIFFRepresentation]];
[[[[[aTrack artworks] data_] set] to:imageData] send];
and get this message instead
2010-03-09 16:46:09.341 Sandbox[2193:a0f] Can't pack object of class NSConcreteData (unsupported type): <4d4d002a 00000000>
In the AppScript documentation, it says that the "data" property of the "artwork" item is a PICTPicture image.
How do I convert an NSImage to a PICT? Am I using the AppScript all wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Appscript 不会桥接 NSImage,部分原因是 NSImage 是 AppKit,而 appscript 仅链接到 Foundation;部分原因是苹果事件的这一领域的使用没有得到很好的规范。理论上,与图像相关的 AEDES 应该包含一个标准的位图数据块,但 ISTR 在处理 iTunes 艺术品时会遇到 PICT 标头的各种麻烦。很乱。
NSData 没有桥接,因为在没有有意义的描述符类型的情况下将数据打包到 AEDES 中基本上是没有意义的。如果要打包 NSData 实例,请使用
+[NSAppleEventDescriptor DescriptorWithDescriptorType:data:]
。另请查看
artwork
类的raw data
属性。这是后来添加的,可能包含更合理形式的图像数据。哦,看一下 EyeTunes 框架;它不像使用 AppleScript/appscript 那样灵活或高效,但我认为它包含将 NSImage 桥接到 AEDescs 的代码。
Appscript doesn't bridge NSImage, in part because NSImage is AppKit and appscript links against Foundation only; in part because this area of Apple events usage is not well specced. In theory, image-related AEDescs should contain a standard block of bitmap data, but ISTR various hassles with PICT headers when dealing with iTunes artworks. It's messy.
NSData isn't bridged because packing data into an AEDesc without a meaningful descriptor type is largely pointless. If you want to pack an NSData instance, use
+[NSAppleEventDescriptor descriptorWithDescriptorType:data:]
.Also take a look at the
artwork
class'sraw data
property. That's a later addition and might contain image data in a more sensible form.Oh, and take a look at the EyeTunes framework; it's not as flexible or efficient as using AppleScript/appscript, but I think it includes code for bridging NSImage to AEDescs.