• 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: NSAffineTransform question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSAffineTransform question


  • Subject: Re: NSAffineTransform question
  • From: Gregory Weston <email@hidden>
  • Date: Wed, 25 Apr 2007 11:28:05 -0400

Janek Priimann wrote:

Right now the image is rotated around (0,0). To fix this problem:

float deltaX = imageRect.size.width * 0.5;
float deltaY = imageRect.size.height * 0.5;

[xform translateXBy:deltaX yBy:deltaY];
[xform rotateByDegrees:90];
[xform translateXBy:-deltaX yBy:-deltaY];

There's actually a bit more to do here. The above code will work if the image is square and the lower-left corner of the result is intended to be at the origin. Since we're dealing with a multiple of 90 degrees, you can just swap the x and y offsets for the final translate (which is, for the OP, the first one in the code line). But the offsets should also be adjusted by the lower-left corner of the intended destination rectangle. And the destination rectangle itself should not be modified ahead of time to reflect the rotated dimensions.


Ewan Delanoy wrote:

   [xform concat];
   [theImage drawInRect:drawingRect fromRect:imageRect
              operation:NSCompositeSourceOver fraction:1.0];
   [xform invert];
   [xform concat];

Those last two lines aren't a reliable way to remove the transform. I've seen what I consider trivial transforms fail to invert. If you want to impose a transform just for a little while:


[NSGraphicsContext saveGraphicsState];
[theTransform concat];
// draw, draw, draw
[NSGraphicsContext restoreGraphicsState];
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Prev by Date: Re: Creating iDisk kind of application.
  • Next by Date: How to draw a rectangle around a (graph) view?
  • Previous by thread: Re: NSAffineTransform question
  • Next by thread: text drawing question
  • Index(es):
    • Date
    • Thread