• 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: NSImage rotation regression?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage rotation regression?


  • Subject: Re: NSImage rotation regression?
  • From: Erik Buck <email@hidden>
  • Date: Mon, 7 Sep 2009 21:16:43 +0000

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSImage rotation regression?
      • From: Marco S Hyman <email@hidden>
  • Prev by Date: Strangest UITable bug
  • Next by Date: Re: NSImage rotation regression?
  • Previous by thread: Re: NSImage rotation regression?
  • Next by thread: Re: NSImage rotation regression?
  • Index(es):
    • Date
    • Thread