swift - Mac Swift - 如何下载图像并将其加载到 NSImageView 中?

标签 swift image macos nsimageview

<分区>

我想从 URL 下载图像并在我的 OSX 快速应用程序中显示它。适用于 iOS 的解决方案不适用于 OSX。

我希望下载图像并将其显示在 NSImageView 中。

最佳答案

简单来说:

let image = NSImage(byReferencingURL:NSURL(string: "http://theinterweb.net/ico/robotics_notes.gif")!)
let imageView = NSImageView()
imageView.image = image

您可以获得Playground Example here ,或者在 Objective-C 中:

NSImage *image = [[NSImage alloc] initByReferencingURL:[NSURL URLWithString:@"http://theinterweb.net/ico/robotics_notes.gif"]];
NSImageView *imageView = [[NSImageView alloc] init];
imageView.image = image;

当然,您可以将 URL 加载到 NSData,然后根据需要转换为 NSImage,就像在 iOS 上一样。

关于swift - Mac Swift - 如何下载图像并将其加载到 NSImageView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38165291/

相关文章:

jquery - 使用 css/jquery 自动定位多个图像以适应

c# - 使用 Image 类在 c# 中丢失图像质量(减少颜色数量)

android - 将图像与 Android 中的 JSON 数据一起上传到 Multipart 中的服务器

python - 无法在 Mac 上安装 Matplotlib

ios - 计算 n 边正多边形的顶点

ios - 无法将 Bool 类型的值分配给类型 String 数据库表示

ios - 如何更改 SCNShape 的大小?

ios - secureTextEntry 不隐藏我的 UITextView 的文本

macos - 无法在 OS X Mountain Lion 上安装 Mono

Python 多进程终止进程