Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.