Rotating an NSImage
Rotating an NSImage
- Subject: Rotating an NSImage
- From: Ian was here <email@hidden>
- Date: Sat, 9 Apr 2005 21:45:45 -0700 (PDT)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
For in case anyone is interested, I figured out how to
rotate an NSImage. I did find some sample code, but it
only rotated in 90 degree angles. It was challenging
to nail this issue down, and I'm grateful for people's
input I received on this mailing list. One last note,
Apple's Transform demo rotates an image inside of an
NSImageView. This following method can be used to
rotate any number of images within an NSView.
- (void)rotateByDegrees:(float)deg
{
_theImage = [NSImage imageNamed:@"beetleship"];
NSSize size = [_theImage size];
NSSize newSize = NSMakeSize( size.width + 20,
size.height + 20 ); // Need to expand the NSImage's
rectagle, so it doesn't get clipped while rotating.
NSAffineTransform *center = [NSAffineTransform
transform];
NSAffineTransform *rot = [NSAffineTransform
transform];
NSImage *newImage = [[NSImage alloc]
initWithSize:newSize];
[center translateXBy:newSize.width / 2
yBy:newSize.height / 2]; // Place origin in the
center of the image's rectangle.
[rot rotateByDegrees:deg]; // Rotate the
image around it's centered origin.
[rot appendTransform:center];
[newImage lockFocus];
[rot concat];
[_theImage drawAtPoint:NSMakePoint( -size.width / 2,
-size.height / 2 ) fromRect:[self spriteRect]
operation:NSCompositeCopy fraction:1.0];
[newImage unlockFocus];
[_theImage release];
_theImage = [newImage retain];
[newImage release];
DrawFlag = YES; // Let your application know that
the image needs to be redrawn. (NOTE: the code that
draws _theImage to the NSView is not in this method.)
}
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
_______________________________________________
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