1

Currently I am working on an NSImageView, on which the user drags and drops an image, and the images gets saved to the disk. I am able to save png and jpeg images, but while saving GIF images, all that is saved is a single frame from the gif. The imageView is able to display the whole animated gif though.

My current implementation to save image from NSImageView to disk is:

   let cgRef = image.CGImageForProposedRect(nil, context: nil, hints: nil)
   let newRep = NSBitmapImageRep(CGImage: cgRef!)
   newRep.size = image.size
   let type = getBitmapImageFileType(imageName.lowercaseString) // getBitmapImageFileType: returns NSBitmapImageFileType
   let properties = type == .NSGIFFileType ? [NSImageLoopCount: 0] : Dictionary<String, AnyObject>()
   let data: NSData = newRep.representationUsingType(type, properties: properties)!
   data.writeToFile(link, atomically: true)

How should I modify this code to be able to save all the frames of GIF to the disk.

Chintan Ghate
  • 179
  • 1
  • 8
  • Possible duplicate of [How to save a NSImage as a new file](http://stackoverflow.com/questions/3038820/how-to-save-a-nsimage-as-a-new-file) – jtbandes Jan 29 '16 at 06:28
  • I have tried that, but every call to `CGImageSourceGetCount(imageSource)` where imageSource is generated from NSImage.image returns `1`, even if the image is gif – Chintan Ghate Jan 29 '16 at 08:09

0 Answers0