On Dec 11, 2008, at 5:43 AM, Glenn Bloom wrote:
Can anyone recommend a best practice for resizing an image to
reduce its
size in terms of both bytes and visible dimensions, retaining the new
smaller image and eliminating the original from memory? In how I
go about
this now, I am concerned about memory and efficiency.
How about something like this?
NSImage* oldImage = GetSomeImage(...);
NSSize newSize = GetDesiredNewSize(oldImage, ...);
NSImage* newImage = [[NSImage alloc] initWithSize:newSize];
[newImage lockFocus];
[oldImage drawInRect:NSMakeRect(0, 0, newSize.width, newSize.height)
fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
[newImage unlockFocus];
[oldImage release];
And depending on how important the resized image quality is, you may
also want to do the following just before the drawInRect call:
[[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com