0

When building a NSImage from a icns file and then painting it on a ImageAndTextCell, it goes very slow. But if I create the NSImage from a png, jpg, etc. it paints very fast.

How to speed it up ? Creating a jpg (etc) from the icns ? Keeping a cache of the created NSImages ?

I appreciate your advise, thanks

Update (from comment below):

It seems as this is the code that is slowing down the execution when a icns file is loaded:

NSImage * image = [ [ [ NSImage alloc ] initWithContentsOfFile:
                      filename ] autorelease ];

called from: -

( id ) tableView : ( NSTableView * ) aTableView objectValueForTableColumn :
       ( NSTableColumn * ) aTableColumn row : ( NSInteger ) rowIndex

If I remove it, then the NSTableView painting is very fast. When it is not a icns file, but a jpg, png, etc. then the painting is very fast. Any hints ?

andand
  • 17,134
  • 11
  • 53
  • 79
  • It seems as this is the code that is slowing down the execution when a icns file is loaded: NSImage * image = [ [ [ NSImage alloc ] initWithContentsOfFile: filename ] autorelease ]; called from: - ( id ) tableView : ( NSTableView * ) aTableView objectValueForTableColumn : ( NSTableColumn * ) aTableColumn row : ( NSInteger ) rowIndex If I remove it, then the NSTableView painting is very fast. When it is not a icns file, but a jpg, png, etc. then the painting is very fast. Any hints ? – Antonio Linares Cañas Jul 04 '12 at 22:50

1 Answers1

2

Solved!

Real fast using:

NSImage * image = [ [ NSWorkspace sharedWorkspace ] iconForFile: bundleName ];  

Very slow using:

NSImage * image = [ [ [ NSImage alloc ] initWithContentsOfFile: filename ] autorelease ];
GDP
  • 8,109
  • 6
  • 45
  • 82