Re: Affine Transform
Re: Affine Transform
- Subject: Re: Affine Transform
- From: Greg Herlihy <email@hidden>
- Date: Sun, 12 Feb 2006 10:23:49 -0800
- Thread-topic: Affine Transform
There's no need for a destination rect. Just draw the rotated image in its
current rect. In other words, delete the following lines of code and the
image will then rotate properly and in the right place:
float newImageWidth = w1 + w2;
float newImageHeight = h1 + h2;
NSRect newImageRect = NSMakeRect(0,0,newImageWidth,newImageHeight);
NSPoint imageOffset = NSMakePoint((newImageWidth - imageWidth)/2,
(newImageHeight - imageHeight)/2);
NSRect dstRect =
NSMakeRect(-imageOffset.x,-imageOffset.y,newImageWidth,newImageHeight);
[self setFrame:dstRect];
[self setBounds:dstRect];
Greg
On 2/12/06 7:32 AM, "Terry Heaford" <email@hidden> wrote:
> degrees = 75;
>
> //calculate new image size & rectangle from original image dims
> plus degrees of rotation
> imageWidth = [image size].width;
> imageHeight = [image size].height;
>
> imageRect = NSMakeRect(0,0,imageWidth,imageHeight);
>
> //calculate via trig the new image size.
> w1 = cos(degrees * pi/180) * imageWidth;
> w2 = cos((90-degrees) * pi/180) * imageHeight;
> h1 = sin(degrees * pi/180) * imageWidth;
> h2 = sin((90-degrees) * pi/180) * imageHeight;
> newImageWidth = w1 + w2;
> newImageHeight = h1 + h2;
>
> newImageRect = NSMakeRect(0,0,newImageWidth,newImageHeight);
>
> //rotation point of image
> centrePoint = NSMakePoint(NSMidX(imageRect), NSMidY(imageRect));
>
> // offset to centre point of new image size.
> imageOffset = NSMakePoint((newImageWidth - imageWidth)/2,
> (newImageHeight - imageHeight)/2);
>
> NSRect dstRect = NSMakeRect(-imageOffset.x,-
> imageOffset.y,newImageWidth,newImageHeight);
>
> [self setFrame:dstRect];
> [self setBounds:dstRect];
>
> [transform translateXBy:centrePoint.x yBy:centrePoint.y];
> [transform rotateByDegrees:degrees];
> [transform translateXBy:-centrePoint.x yBy:-centrePoint.y];
> [transform concat];
>
> [image drawInRect:imageRect fromRect:imageRect
> operation:NSCompositeCopy fraction:opacity];
_______________________________________________
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