无法从具有NSImage(byReferencingFile:)的文件中加载NSImageView图像 [英] Can not load NSImageView image from file with NSImage(byReferencingFile: )

查看:234
本文介绍了无法从具有NSImage(byReferencingFile:)的文件中加载NSImageView图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我要将光盘(/Users/me/Desktop/image.png )中的图像设置为具有NSImage(byReferencingFile: )NSImageView的图像时,它不会显示.

When I want to set a image from my disc (/Users/me/Desktop/image.png) to the image of my NSImageView with NSImage(byReferencingFile: ) it does not show it.

当我尝试NSImage(named: )使用存储在资产文件夹中的图像进行操作时,它会起作用.

When I try NSImage(named: ) with an image stored in the assets-folder, it works.

viewController中的代码

class ViewController: NSViewController {
    @IBOutlet var imageView: NSImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        imageView.image = NSImage(byReferencingFile: "/Users/me/Desktop/image.png")
    }    
}

imageView 会填满整个窗口.

所以我想加载存储在磁盘上或指定URL上的图像.

So I want to load the image stored on disk or at a specified URL.

推荐答案

Willeke 帮助我找到了解决方案.我必须将权利文件中的App SandboxYES切换到NO

Willeke helped me to find the solution. I had to switch App Sandbox in the entitlements-file from YES to NO

这篇关于无法从具有NSImage(byReferencingFile:)的文件中加载NSImageView图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆