如何从已知图像路径显示图像 - SwiftUI

时间:2021-01-28 01:52:17

标签: swift macos swiftui

我有一组图像 URL(全部来自存储,而不是互联网)。如何显示图像本身? 简化代码:

@Binding var files:[URL]//Array of image URLs taken from an NSOpenPanel instance

Form{
    if files.count>0{
        Image(files[0].path)//Problem
    }
}

1 个答案:

答案 0 :(得分:1)

你说 NSOpenPanel,所以我在这里假设我们不需要担心等待通过网络加载图像:

if let nsImage = NSImage(contentsOf: url) {
  Image(nsImage: nsImage)
}
相关问题