2010-03-10 64 views
1

aTrack是一個ITReference *對象,value是一個NSImage *對象,通過一個URL初始化爲一個jpeg。如何使用obj-c AppScript將作品添加到iTunes曲目?

[[[[[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都錯了嗎?

回答

0

Appscript不會橋接NSImage,部分原因是NSImage是AppKit,而appscript僅鏈接到Foundation;部分原因是蘋果事件使用的這一領域並不完善。從理論上講,與圖像相關的AEDescs應該包含一個標準的位圖數據塊,但ISTR在處理iTunes藝術品時會遇到各種帶PICT標頭的麻煩。這很混亂。

NSData未橋接,因爲將數據打包到AEDesc中而沒有有意義的描述符類型在很大程度上毫無意義。如果您想打包一個NSData實例,請使用+[NSAppleEventDescriptor descriptorWithDescriptorType:data:]

也看看artwork類的raw data屬性。這是後來的增加,可能包含更合理形式的圖像數據。

哦,看看EyeTunes框架;它不像使用AppleScript/appscript那樣靈活或高效,但我認爲它包含將NSImage橋接到AEDescs的代碼。

相關問題