10

I'm using an NSImageView to display an animated GIF with around 80 frames, each frame being 20ms long. NSImageView can display the GIF animation right 'out of the box', but the problem is that it needs too much CPU, around 10% continuously (on my core i5 proc). Instruments shows that it spends a lot of CPU time decoding the GIF.

To make it more efficient, I have tried the following without much success:

  • putting the frames inside a QTMovie and playing it (uses 4% for my process and another 15% for the QTKitServer process that plays the movie)

  • drawing directly to the view with CGContextDrawImage (~5% CPU usage) - I didn't export the GIF's frames, I just created a CGImageRef from a 30x30px .png I had lying around.

I don't know what else to try. Subclassing NSImageView and somehow caching the images sounds like a good idea but, alas, I'm a beginner in Cocoa... Any ideas would be much appreciated. Thanks!

Victor Bogdan
  • 2,022
  • 24
  • 33
  • 3
    Have you tried `-[NSImage setCacheMode:]` with an `NSImageCacheAlways` argument? –  Apr 12 '11 at 01:11
  • 3
    Following your suggestion, I rewrote my NSImageView subclass and ended up with the CPU usage at about half of what it was before. I've checked and using `setCacheMode:` on the individual GIF frames that I'm cycling through doesn't make any visible difference. Your input helped me nevertheless, so thanks! – Victor Bogdan Apr 14 '11 at 19:50
  • How exactly did you solve this? This is an interesting problem and I'm trying to tackle it as well. What did you change in your NSImageView subclass? – AlexQueue Aug 10 '13 at 21:17
  • I don't have the code around anymore, but you're better off looking at NSImage/UIImage and its animation support. There also seem to be several 3rd party solutions for working with animated GIFs and NSImage. Here's one: https://github.com/mayoff/uiimage-from-animated-gif – Victor Bogdan Aug 12 '13 at 08:52

0 Answers0