• 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: Image Scaling Code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Image Scaling Code


  • Subject: Re: Image Scaling Code
  • From: Tom Waters <email@hidden>
  • Date: Fri, 13 Jul 2001 22:25:45 -0700

On Friday, July 13, 2001, at 09:52 PM, Michael Horn wrote:
>
> Anyone know of an example of quality image scaling code? Perhaps using
> Quicktime?
>
> What I have is a fairly large JPG (1600 x 1200) and I would like to
> scale it down and create a thumbnail for it.

You need to use drawInRect... here's some code (written in email and not
tested) that might work:

const int thumbMax = 128;
NSImage *image = [NSImage imageNamed: @"myBigImage.jpg"];
NSSize size = [image size];
NSSize thumbSize = size.width > size.height ?
NSMakeSize(thumbMax, thumbMax * size.height / size.width) :
NSMakeSize(thumbMax * size.width / size.height, thumbMax);
NSImage *thumbnail = [[NSImage alloc] initWithSize: thumbSize];
[thumbnail lockFocus];
[image drawInRect: NSMakeRect(0, 0, thumbSize.width, thumbSize.height)
fromRect: NSMakeRect(0, 0, [image size].width, [image size].height)
operation: NSCompositeCopy fraction: 1.0];
[thumbnail unlockFocus];

Now you should have the thumbnail with the right pixels in it, i'll
leave it as an exercise to display it and/or save it to disk. (there
might be some issue with the image being upside-down or drawn in the
wrong place... depending on if your view and/or the images are
"flipped", see isFlipped)


References: 
 >Image Scaling Code (From: Michael Horn <email@hidden>)

  • Prev by Date: Re: retainCount
  • Next by Date: Frameworks and global variables
  • Previous by thread: Image Scaling Code
  • Next by thread: AuthorizationCreate
  • Index(es):
    • Date
    • Thread