macos - 将 gif 图像粘贴到 NSPasteboard

标签 macos swift

我正在开发 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/

相关文章:

python - 在 Mac OSX 上的 virtualenv 中为 Python 3 安装 pip?

macos - dart2js不会抛出此类文件或目录错误

macos - 通过 docker-machine 运行带有数据卷的 postgres 容器

linux - 更新 Ubuntu guest 后 Vagrant "ssh_exchange_identification: Connection closed by remote host"

objective-c - 在 NSTableView 中加载图像时的奇怪行为

ios - Swift:条件编译标志必须是有效的 Swift 标识符

Swift 不能在结构内部使用任何变量

swift - 将 Swift 字典转换为 JSON 字符串时的 try-catch 位置

swift - NSViewController 未发布

ios - 如何为内部测试人员在 Testflight 中创建多个构建