Design Element
Comment on "Proportional Scaling with NSImage"
by Scott Stevenson — Sep 30
@Pieter Omvlee: Just wondering, why not make a copy and use the setSize: method of NSImage

In the context where this was originally conceived, the idea was to take very, very large images and resize them into 64x64 pixel thumbnails. In that case, you absolutely want to resample so you're not pulling all that extra image data around.

In any case, locking focus is not that slow if you use it in the way it's likely intended. It's probably best to not do it 30 times per second, but if you're caching an image (which is what happens in SimplePicture), it's absolutely fine.

@Blain: I was about to say, you could probably make things even faster by abstracting out the nsimage, and making a C-style function (...) Given that the next step after -imageByScaling... would most likely be to draw this new image in another context

That's a completely valid approach. In fact, you could use that sort of utility function inside of this one. But the point of this particular method is to make a resized/cached copy of the original image for later use.

@Peter Hosey: Do this using the Lanczos Transform filter in Core Image. Programmatically

Admittedly, I either didn't know or forgot about this, but there are some cases where you need to NSImage instead of CIImage (trust me! :). And other cases where it's just more convenient.

Still, thanks for bringing it up.
Back to "Proportional Scaling with NSImage"
Design Element

Copyright © Scott Stevenson 2004-2015