• 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: How to scale an NSImage (with smaller memory size)?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to scale an NSImage (with smaller memory size)?


  • Subject: Re: How to scale an NSImage (with smaller memory size)?
  • From: John Pannell <email@hidden>
  • Date: Thu, 30 Sep 2004 19:56:48 -0600

There are other ways to perform this task (i.e. vImage, or CoreImage in Tiger?), but the following has worked for me. "theImage" is the NSImage you wish to thumbnail.

NSImage *thumbImage = [[NSImage alloc] initWithSize:NSMakeSize(128, 128)];

NSAffineTransform *at = [NSAffineTransform transform];
[theImage setScalesWhenResized:YES];
heightFactor = 128.0/[theImage size].height;
widthFactor = 128.0/[theImage size].width;
if(heightFactor > widthFactor){
scale = widthFactor;
} else {
scale = heightFactor;
}


[at scaleBy:scale];


[thumbImage lockFocus];
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationLow];
[theImage setSize:[at transformSize:[theImage size]]];
[theImage compositeToPoint:NSMakePoint((128-[theImage size].width)/2 , (128-[theImage size].height)/2) operation:NSCompositeCopy];
[thumbImage unlockFocus];

At this point, thumbImage is now an NSImage you can work with further. Hope this helps!

John

On Sep 30, 2004, at 4:00 PM, Peter Schmidt wrote:

Hello List,

How can I make from an NSImage (of a JPEG file) a smaller version, e.g. from a 1000 * 1000 pixel picture, a 128 * 128 pixel picture and store this into a new NSImage?

Greetings from Germany,
Peter

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Boggled By Bindings
  • Next by Date: Re: Boggled By Bindings
  • Previous by thread: Re: Boggled By Bindings
  • Index(es):
    • Date
    • Thread