Design Element
Comment on "Proportional Scaling with NSImage"
by Scott Stevenson — Oct 01
@Peter Hosey: In such cases, you can use NSCIImageRep to wrap the CIImage inside an NSImage

That doesn't work in cases where you want to specifically avoid using CoreImage, which does happen. But again, it's good to mention.

@Blain: Is there any advantage or disadvantage to adding an ImageRep instead of generating a new image that I'm not seeing?

I admit I'm not quite sure what you mean. The goal in the case of SimplePicture was to open the full-size image, resample it as a thumbnail, then release the full size version to save memory.

You could draw the thumbnail into an NSBitmapImageRep, add that to the original image, then remove the full-size NSBitmapImageRep, but I'm not sure you'd end up ahead.

There are certainly cases where you want both small and large versions of the same source image, but I think you're better off just making separate NSImages in that cases, rather than one image with multiple bitmap reps. I think it would up being a lot of work to manage the reps since they're not keyed by size or anything. You'd have to enumerate through them each time to find the right one. The whole idea behind the NSImage/NSImageRep relationship is to encapsulate the details when possible.

Typically, I think you'd want multiple reps if you need different classes of reps. That is, an NSBitmapImageRep, an NSCIImageRep, and so on inside of one NSImage. I'm not so sure you'd want multiple instances of the same kind.

You do bring up an interesting point, though. If you add a NSBitmapImageRep of 500x500, and another at 64x64, will NSImage be smart enough to use the 64x64 version (the bitmap rep, not the cache rep) if you draw at that size? Worth an experiment.

I'm still not seeing any goofball mistakes. What was it?

Nothing to see here.
Back to "Proportional Scaling with NSImage"
Design Element

Copyright © Scott Stevenson 2004-2015