来自网站URL的NSImage

nos*_*e25 4 url cocoa nsimage nsimageview

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

谢谢

Mic*_*zer 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.
Run Code Online (Sandbox Code Playgroud)

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

  • happyCoding:`initWithContentsOfURL:`是一个实例方法.您需要将该消息发送到实例 - 特别是从`alloc`收到的实例.NSImage*类*不响应它(即,它不是类方法),正如该异常消息所证明的那样. (2认同)