NSImage setSize and setScaleWhenResized

The setSize of NSImage behaves differently on the Leopard and the Tiger.
According to the NSImage class reference for the Leopard, it says :

“Changing the size of an NSImage after it has been used effectively resizes the image.”

It behaves as such on the Leopard, but not on the Tiger.
On the Tiger, the setSize doesn’t resize an image.

Take a look at the source code below.

NSImage *anImage;
NSSize imageSize;
NSString *imagePath;

imagePath = [[NSBundle mainBulde] pathForImageResource:@"myLogo.eps"];
anImage = [[NSImage alloc] initWithContentsOfFile:imagePath];
imageSize = [anImage size];
imageSize.width *= 0.3;
imageSize.height *= 0.3;
[anImage setScaleWhenResized:YES]; // For the Tiger
[anImage setSize:imageSize];

The eps format is a postscript format with which a scaling can be used.
The Leopard version of the setSize method of the NSImage automatically scales and draws the image as such.
However, on the Tiger the setScaleWhenResized with YES as its parameter should be explicitly called.
Documentation for the Tiger explains this much better.

For other approaches, Sci-Fi Hi-Fi hosted a good article.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: