Re: Sample code to rotate an NSImage
Re: Sample code to rotate an NSImage
- Subject: Re: Sample code to rotate an NSImage
- From: Henry McGilton <email@hidden>
- Date: Thu, 18 Sep 2003 11:18:14 -0700
On Thursday, September 18, 2003, at 10:06 AM, Dave Riggle wrote:
The following routine works, but I don't like it. The transformations
seem to get applied in reverse order. Is that the way
NSAffineTransform is supposed to work?
Dave
+ (NSImage *)rotate:(NSImage *)image byAngle:(int)degrees
{
if (degrees == 0) {
return image;
} else {
NSSize beforeSize = [image size];
NSSize afterSize = degrees == 90 || degrees == -90 ?
NSMakeSize(beforeSize.height, beforeSize.width) : beforeSize;
NSImage* newImage = [[[NSImage alloc] initWithSize:afterSize]
autorelease];
NSAffineTransform* trans = [NSAffineTransform transform];
[newImage lockFocus];
[trans translateXBy:afterSize.width * 0.5 yBy:afterSize.height
* 0.5];
[trans rotateByDegrees:degrees];
[trans translateXBy:-beforeSize.width * 0.5
yBy:-beforeSize.height * 0.5];
<<<<<<<< ==================================
[trans set];
<<<<<<<< ==================================
[image drawAtPoint:NSZeroPoint
fromRect:NSMakeRect(0, 0, beforeSize.width,
beforeSize.height)
operation:NSCompositeCopy
fraction:1.0];
[newImage unlockFocus];
return newImage;
}
}
The set looks suspicious. Try using concat instead and see
what happens . . .
Best Wishes,
........ Henry
===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden |
http://www.trilithon.com
|
===============================+============================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.