I put a fixed size icon based on an image of arbitrary size in NSOutlineView using NSImageCell.
NSImageCell scales the image nicely, but I can't find a way to add extras around the scaled image. The lines look ugly before my eyes without indentation.
My first pass to fix this problem was to create a new image with a constant size, paste its borders to fill, and then use drawInRect: fromRect: operation: fraction: to draw a smaller version of the original icon.
This is great for square images. I would have guessed that in NSImage there would be a convenience method to draw a centered, constant-scaled version of the image in this rectangle, but I can not find it.
Obviously, I can calculate the corresponding rectangle with the same aspect ratio as the original image, but I would not reinvent the wheel ...
source share