来自NSData信息的NSImage

时间:2012-12-03 10:40:41

标签: objective-c macos cocoa

我有一个NSData对象,据说包含TIFF格式的图像数据。 Here是输出的示例(位于左上角的框中)。

然而,当我NSLog出来时,我得到以下内容:

<NSImage 0x10013f620 Size={200, 200} Reps=(
    "NSBitmapImageRep 0x1001220d0 Size={200, 200} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=200x200 Alpha=NO Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x100150070"
)>

这让我觉得它实际上可能是BitmapImage。

无论如何,当我执行以下操作时:

NSData *artworkData;
NSImage *image;
artworkData = [self.currentTrack artwork]; // actually sets memory, like expected
image = [[NSImage alloc] initWithData:artworkData]; // causes the error

我收到此错误:

2012-12-03 02:39:56.263 test[92556:303] -[NSImage length]: unrecognized selector sent to instance 0x10064ec90
2012-12-03 02:39:56.264 test[92556:303] -[NSImage length]: unrecognized selector sent to instance 0x10064ec90

有什么想法吗?这一直困扰着我一段时间。

谢谢!

1 个答案:

答案 0 :(得分:1)

您确定要处理NSData对象吗?日志输出中的对象不是数据,它已经是NSImage。因此,尝试将其用作-[NSImage initWithData:]的参数将失败。

相关问题