The -bestRepresentationFirDrevice: method is doing nothing better than [anImage size] would do for you.

You are not doing anything useful with rotatedSize in your code.

Your test for if (degrees == 180.0) is completely pointless. If you were going to do it anyway, you should be looking for 90, 180, and 270 degrees as well as all other multiples of 90 deg.

Why do you copy originalSize into rect?



How about the following alternative code typed in Mail

@implementation NSImage (MYAdditions)

- (NSImage *)copyRotatedByDegrees:(CGFloat)degrees
{
   NSSize originalSize = [self size];
NSRect originalRect = NSMakeRect(0.0, 0.0, originalSize.width, originalSize.height);
   NSSize halfOriginalSize = NSMakeSize(originalSize.width / 2.0,
                                        originalSize.height / 2.0);

   NSAffineTransform* transform = [NSAffineTransform transform];
   [transform rotateByDegrees: fmod(degrees, 45.0)];

   NSSize halfRotatedSize = [transform transformSize:halfOriginalSize];
NSSize rotatedSize = NSMakeSize( (2.0 * halfRotatedSize.width), (2.0 * halfRotatedSize.height));
   [transform rotateByDegrees: -fmod(degrees, 45.0)];

NSImage *rotatedImage = [[[NSImage alloc] initWithSize:rotatedSize] autorelease];
   [rotatedImage setBackgroundColor:[NSColor clearColor]];

   [rotatedImage lockFocus];
[transform translateXBy:halfRotatedSize.width yBy:halfRotatedSize.height];
   [transform rotateByDegrees: degrees];
[transform translateXBy: -halfRotatedSize.width yBy: - halfRotatedSize.height];
   [transform concat];
   [self drawAtPoint:NSZeroPoint fromRect:originalRect
           operation:NSCompositeSourceOver fraction:1.0];
   [[NSColor blackColor] set];
   NSFrameRect(originalRect);
   [rotatedImage unlockFocus];

   return rotatedImage;
}

@end




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to