Re: Problems rotating an NSImage
Re: Problems rotating an NSImage
- Subject: Re: Problems rotating an NSImage
- From: Henry McGilton <email@hidden>
- Date: Sat, 5 Mar 2005 11:52:24 -0800
On Mar 5, 2005, at 3:10 AM, Arthur VIGAN wrote:
Hi,
I have read the archives about how to rotate an NSImage, but I still
have problems. I want to rotate my image by an angle of 90° or -90°. I
cannot rotate the whole view, so I tried to composite my image
(currentImage) into another (targetImage):
NSImage *targetImage;
NSAffineTransform *trans=[NSAffineTransform transform];
NSSize currentImageSize=[currentImage size];
// the new image is rotated by 90°, so I exchange width and height
targetImage=[[NSImage alloc]
initWithSize:
NSMakeSize(currentImageSize.height,currentImageSize.width)];
[targetImage lockFocus];
// apply the transform
[trans translateXBy:currentImageSize.height/2.0
yBy:currentImageSize.width/2.0];
[trans rotateByDegrees:(float)theta];
[trans translateXBy:-currentImageSize.height/2.0
yBy:-currentImageSize.width/2.0];
You need to change that above line:
[trans translateXBy: -(currentImageSize.width / 2.0) yBy:
-(currentImageSize.height / 2.0)];
After the rotate, the x and y coordinates are swapped . . .
For arbitary rotations other than 90°, it'll be somewhat more tricky .
. .
[trans set];
[currentImage drawAtPoint:NSMakePoint(0.0,0.0)
fromRect:NSMakeRect(0.0,0.0,[targetImage
size].height,[targetImage size].width)
operation:NSCompositeSourceOver
fraction:1.0];
[targetImage unlockFocus];
[currentImage release];
currentImage=targetImage;
The transform seems to work fine, but my image is cropped... Does
someone see what is wrong with my code?
Cheers,
........ Henry
===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden | http://www.trilithon.com
|
===============================+============================
===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden | http://www.trilithon.com
|
===============================+============================
_______________________________________________
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