• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Resizing an image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Resizing an image (From: "Glenn Bloom" <email@hidden>)

  • Prev by Date: Re: Countdown With NSTimer - Hours, Minutes, Seconds Remaining?
  • Next by Date: Re: Is it useful to make a 64 bit app? [Was]: How can users check if their mac is 64-bit-capable?
  • Previous by thread: Resizing an image
  • Next by thread: Re: Resizing an image
  • Index(es):
    • Date
    • Thread