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

Re: Affine Transform


  • Subject: Re: Affine Transform
  • From: Greg Herlihy <email@hidden>
  • Date: Sat, 11 Feb 2006 17:36:54 -0800
  • Thread-topic: Affine Transform

Since the image is rotated about the bounds origin, rotating it with the
default origin (in the upper left hand corner) tends to rotate the image off
the screen completely. To rotate the image in place, I would move the
bounds' origin to the center of the current viewable area:

    [self setBoundsOrigin:NSMakePoint(-NSWidth([self frame])/2.0f,
-NSHeight([self frame])/2.0f)];

And also draw the image in the same centered location.

If the view is flipped, then do not negate the call to NSHeight().

Hope that helps.

Greg

On 2/11/06 12:29 PM, "Terry Heaford" <email@hidden> wrote:

> A newbie question:
>
> I am really struggling with affine transforms to rotate an image
> contained in an NSView which is a subview of a scrollview.
>
> The image is larger than than the visible size of the scrollview.
>
> The code I have from drawRect is below:
>
> if (image)
> {
> deg = 45;
>
> NSRect imageRect = NSMakeRect(0,0,[image size].width,[image
> size].height);
>
> NSPoint imageDrawPoint = NSMakePoint([self visibleRect].size.width/
> 2, [self visibleRect].size.height/2);
>
> NSAffineTransform *trans = [NSAffineTransform transform];
> [trans translateXBy:imageDrawPoint.x yBy:imageDrawPoint.y];
> [trans rotateByDegrees:deg];
> [trans translateXBy:-imageDrawPoint.x yBy:-imageDrawPoint.y];
> [trans concat];
>
> [image drawAtPoint:NSZeroPoint fromRect:imageRect
> operation:NSCompositeCopy fraction:opacity];
>
> }
>
> This seems to rotate the image correctly but how do I size the frame
> or the bounds (not sure which or both) to the correct size for the
> rotated image allowing it to be scrolled within the scrollview and
> how do I locate the image within the frame correctly.
>
> Thanks in advance
>
> Terry
>
>
>  _______________________________________________
> 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


 _______________________________________________
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

References: 
 >Affine Transform (From: Terry Heaford <email@hidden>)

  • Prev by Date: Re: Problem moving subview within superview
  • Next by Date: highlightling custom table header cell on mouse clicks
  • Previous by thread: Affine Transform
  • Next by thread: Re: Affine Transform
  • Index(es):
    • Date
    • Thread