2010-04-18 61 views
4

我需要从url创建一个NSImage,然后将其设置为我的应用程序中的图像视图。我尝试了一些我在网上找到的代码,但没有奏效。如果有人知道如何做到这一点,任何帮助都会很棒。从网站URL的NSImage

感谢

回答

5

你会想看看

initWithContentsOfURL: 
Initializes and returns an NSImage instance with the contents of the specified URL. 

- (id)initWithContentsOfURL:(NSURL *)aURL 

Parameters 
aUrl 
The URL identifying the image. 
Return Value 
An initialized NSImage instance, or nil if the method cannot create an image representation from the contents of the specified URL. 

http://developer.apple.com/mac/library/documentation/cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html#//apple_ref/occ/instm/NSImage/initWithContentsOfURL

+0

嗯,我得到一个错误,当我尝试 NSImage中* MYIMAGE = [NSImage中initWithContentsOfURL:[NSURL URLWithString :@ “http://somesite.com/image.png”]];有任何想法吗? – nosedive25 2010-04-18 02:42:21

+0

什么类型的错误? – 2010-04-18 02:48:40

+0

我得到了+ [NSImage initWithContentsOfURL:]:无法识别的选择器发送到类0x7fff704e6340 – nosedive25 2010-04-18 02:50:49