• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reflecting image using NSAffineTransform
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reflecting image using NSAffineTransform


  • Subject: Re: Reflecting image using NSAffineTransform
  • From: Chris Lewis <email@hidden>
  • Date: Thu, 28 Jul 2005 00:06:39 +0100

John,
Thank you for the help, the origin did need to be moved! However,
where should this new origin be set to be at?

The image size I recieve is set to be the same size as the NSImageView
it outputs to. Trying this:

    NSSize dimensions = [cameraView frame].size;
//SNIP//
	[aFrame drawAtPoint:NSMakePoint((-dimensions.width),0)
fromRect:NSMakeRect(0,0, dimensions.width, dimensions.height)
operation:NSCompositeCopy fraction:1.0];

Draws a half and half image, one flipped and one not. Obviously, my
new one is being overlayed. The new, wonderfully flipped image (it's
fast too, I thought this was going to be really slow, but it's doing
30fps! Great!) is only covering the *left* half of the screen. I tried
various permutations on 2 in order to get it centred:

(-dimensions.width * 2) - No flipped image
(-dimensions.width * -2) -No flipped image
(-dimensions.width * -0.5) - No flipped image
(-dimesions.width * 0.5) - Flipped image takes up 1.4 of the screen on
the left hand side.

So it seems that I should need to do (-dimensions.width * 2), but its
just not showing anything.

Where should the origin go John? Thank you ever so much, you've been a star.
Chris Lewis

On 27/07/05, John C. Randolph <email@hidden> wrote:
>
> 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

  • Follow-Ups:
    • Re: Reflecting image using NSAffineTransform
      • From: "John C. Randolph" <email@hidden>
References: 
 >Reflecting image using NSAffineTransform (From: Chris Lewis <email@hidden>)
 >Re: Reflecting image using NSAffineTransform (From: "John C. Randolph" <email@hidden>)

  • Prev by Date: Re: .webarchive format
  • Next by Date: Re: Another rookie core data question
  • Previous by thread: Re: Reflecting image using NSAffineTransform
  • Next by thread: Re: Reflecting image using NSAffineTransform
  • Index(es):
    • Date
    • Thread