Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reflecting image using NSAffineTransform



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?

Any help to flip this darn image would be very much appreciated, thank
you ever so much,
Chris Lewis
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.