Re: Resizing an image
Re: Resizing an image
- Subject: Re: Resizing an image
- From: Steve Christensen <email@hidden>
- Date: Thu, 11 Dec 2008 11:44:31 -0800
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 (email@hidden)
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:
This email sent to email@hidden