我正在开发 osx 应用程序。我想将 Gif 图像粘贴到粘贴板中。我该怎么做?
我有的是
- NSImage
- NSPasteboard
我想做的是将该图像粘贴到粘贴板中。我可以粘贴 PNG 图片,但我需要粘贴 GIF 图片。
我现有的代码
let imageURL = imageObject.imageURL!
let fileName = imageURL.lastPathComponent
var saveURL = NSURL(string: "file://" + NSTemporaryDirectory())
saveURL = saveURL?.URLByAppendingPathComponent(fileName!)
// I have data now
let data = NSData(contentsOfURL: imageURL)
pasteboard.declareTypes([NSTIFFPboardType], owner: nil)
pasteboard.setData(data!, forType: "com.compuserve.gif")
最佳答案
大约 10 年前,同样的人问过 How do I put a GIF onto an NSPasteboard? 在 Apple 讨论组中,这是我的答案。尽管 10 岁了并且 NSPasteboard 方法从那时起发生了变化,但我的答案仍然有效。我承认:我的建议有点脏。
关于macos - 将 gif 图像粘贴到 NSPasteboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31599738/