• 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: Sample code to rotate an NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Sample code to rotate an NSImage (From: Dave Riggle <email@hidden>)

  • Prev by Date: Re: NSSaveView and odd NSCFArray errors
  • Next by Date: using MIDI signals to control the computer?
  • Previous by thread: Sample code to rotate an NSImage
  • Next by thread: using MIDI signals to control the computer?
  • Index(es):
    • Date
    • Thread