I\'m having a little bit of a problem scaling my images to a properly predefined size. I was wondering - since it is purely mathematics, if there\'s some sort of common logi
Here is how I do it:
+ (NSSize) scaleHeight:(NSSize)origSize
newHeight:(CGFloat)height {
NSSize newSize = NSZeroSize;
if ( origSize.height == 0 ) return newSize;
newSize.height = height;
CGFloat factor = ( height / origSize.height );
newSize.width = (origSize.width * factor );
return newSize;
}
+ (NSSize) scaleWidth:(NSSize)origSize
newWidth:(CGFloat)width {
NSSize newSize = NSZeroSize;
if ( origSize.width == 0 ) return newSize;
newSize.width = width;
CGFloat factor = ( width / origSize.width );
newSize.height = (origSize.height * factor );
return newSize;
}