Re: Reflecting image using NSAffineTransform
Re: Reflecting image using NSAffineTransform
- Subject: Re: Reflecting image using NSAffineTransform
- From: "John C. Randolph" <email@hidden>
- Date: Wed, 27 Jul 2005 15:37:59 -0700
On Jul 27, 2005, at 1:04 PM, Chris Lewis wrote:
Hello there,
I've been teaching myself Cocoa over the past few weeks, and have
found the archives of this mailing list invaluable, so I'd like to
start by thanking everyone for all their great answers! I've got
myself pretty stuck, so I was wondering if anyone could help me out?
I am feeding in images from my iSight using the Delicious
CocoaSequenceGrabber framework. It lets me deal with things frame by
frame, which is pretty neat. You may have noticed iChat does a
horizontal flip of the image, because it looks weird to the user to
move your hand left, but on screen it goes right. I'm trying to do
this too, but failing miserably. I've been using tips from the
archives, which told me to scale X by -1, but it's not playing ball.
Here it is:
NSAffineTransform *flipper = [NSAffineTransform transform];
NSSize dimensions = [cameraView frame].size;
[aFrame lockFocus];
[flipper scaleXBy:-1.0 yBy:1.0];
[flipper set];
[aFrame drawAtPoint:NSMakePoint(0,0) fromRect:NSMakeRect(0,0,
dimensions.width, dimensions.height) operation:NSCompositeCopy
fraction:1.0];
[aFrame unlockFocus];
[cameraView setImage:aFrame];
aFrame is the NSImage passed to the delegate function called whenever
a frame is going to be displayed. cameraView is an NSImageView where
the image is shown.
The transform just doesn't apply to the image (I grabbed the rectangle
drawing thing off the mailing list, I would never have worked out that
was what I needed to do). If I set both setXBy and yBy to a positive
same number, it does the scaling. If I set it to negative, or have
different positive numbers for x and y it doesn't scale or flip or
anything. I don't understand why scaling should work in that way,
surely scaling negatively is reducing the image?
No, scaling to less than 1.0 reduces the image. Negative numbers
will shift the image to the opposite side of the axis in question.
When you have negative scaling terms in your affine transform, you
also need to move the origin.
-jcr
John C. Randolph <email@hidden> (408) 914-0013
Roaming Cocoa Engineer,
Available for your projects at great Expense and Inconvenience.
_______________________________________________
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