Insert gif image into NSPasteboard
I am developing an osx application. I want to insert a Gif image into cardboard. How can i do this?
I have
- NSImage
- NSPasteboard
What I want to do is paste this image into cardboard. I can insert a PNG image, but I need to insert a GIF image .
My existing code
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")
+3
source to share
2 answers
About 10 years ago the same one asked How to post GIF on NSPasteboard? in Apple's discussion group and here's my answer. Although 10 years ago and the methods of NSPasteboard have changed since then, my answer still works. I confess: my advice is a little messy.
+1
source to share
Ok, I got started after spending 6 hours on the internet.
Basically, I need to upload an image file and insert it as a filename.
let imageURL = imageObject.imageURL!
let fileName = imageURL.lastPathComponent
var saveURL = NSURL(string: "file://" + NSTemporaryDirectory())
saveURL = saveURL?.URLByAppendingPathComponent(fileName!)
let data = NSData(contentsOfURL: imageURL)
data?.writeToURL(saveURL!, atomically: true)
pasteboard.declareTypes([NSFilenamesPboardType], owner: nil)
pasteboard.writeObjects([saveURL!])
-1
source to share