Re: Problems rotating an NSImage
Re: Problems rotating an NSImage
- Subject: Re: Problems rotating an NSImage
- From: Serge Meynard <email@hidden>
- Date: Sat, 05 Mar 2005 13:18:51 -0500
First, the fromRect is in terms of the source image, so I think you
want to rewrite this as
[currentImage drawAtPoint:NSMakePoint(0.0,0.0)
fromRect:NSMakeRect(0.0, 0.0, currentImageSize.width,
currentImageSize.height)
operation:NSCompositeSourceOver
fraction:1.0];
Second, I would suggest using compositeToPoint instead; I'm not 100%
clear on what the difference is between the two (maybe someone can
explain it?) but they certainly don't work the same and I've found
compositeToPoint works better for me.
[currentImage compositeToPoint:NSMakePoint(0.0,0.0)
fromRect:NSMakeRect(0.0, 0.0,
currentImageSize.width, currentImageSize.height)
operation:NSCompositeSourceOver];
Let me know if this helps.
Serge
On Mar 5, 2005, at 06:10, 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];
[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:
email@hidden
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