Problems rotating an NSImage
Problems rotating an NSImage
- Subject: Problems rotating an NSImage
- From: Arthur VIGAN <email@hidden>
- Date: Sat, 5 Mar 2005 12:10:36 +0100
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];
[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?
Thanks a lot in advance,
-- Arthur;
--
Arthur VIGAN
<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