June 25,2005
Resize NSImage
NSImage *resizedImage = [[NSImage alloc] initWithSize: theNewSize];
// lock focus on resized image
[resizedImage lockFocus];
[NSGraphicsContext saveGraphicsState];
// set image interpolation -> high (better resize quality)
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
// src draw to resized
[image drawInRect:NSMakeRect(0.0,0.0,theNewSize.width, theNewSize.height)
fromRect:NSMakeRect(0.0,0.0,[image size].width, [image size].height)
operation:NSCompositeCopy fraction:1.0];
[NSGraphicsContext restoreGraphicsState];
[resizedImage unlockFocus];
// lock focus on resized image
[resizedImage lockFocus];
[NSGraphicsContext saveGraphicsState];
// set image interpolation -> high (better resize quality)
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
// src draw to resized
[image drawInRect:NSMakeRect(0.0,0.0,theNewSize.width, theNewSize.height)
fromRect:NSMakeRect(0.0,0.0,[image size].width, [image size].height)
operation:NSCompositeCopy fraction:1.0];
[NSGraphicsContext restoreGraphicsState];
[resizedImage unlockFocus];
引用URL
http://cgi.blog.roodo.com/trackback/216833