将gif图像粘贴到NSPasteboard中 [英] Paste gif image into NSPasteboard

查看:251
本文介绍了将gif图像粘贴到NSPasteboard中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发osx应用程序.我想将 Gif 图片粘贴到粘贴板中.我该怎么办?

I am developing osx application. I want to paste an Gif image into pasteboard. How can I do that?

我拥有的是

  • NSImage
  • NSPasteboard

我想做的就是将该图像粘贴到粘贴板中.我可以粘贴 PNG 图片,但我需要粘贴 GIF 图片.

What I want to do is to paste that image into pasteboard. I am able to paste PNG image but what I need is to paste GIF image.

我现有的代码

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年前,同一个人问

About 10 years ago same one asked How do I put a GIF onto an NSPasteboard? in an Apple discussion group and here is my answer. Although 10 years old and the NSPasteboard methods changed since that time my answer still works. I confess: my advice is a bit dirty.

这篇关于将gif图像粘贴到NSPasteboard中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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