1

i have an UIImageView that the user can rotate and resize touching the screen. I want apply the same changes the user has made on the UIImageView to the UIImage inside it. Then i will use the UIImage for masking another image.

Please can you explain me what is the correct procedure for doing that?

The main problem is that i can't apply directly the Affine Transformation Matrix of the UIImageView to the [UIImage CGImage], because they use a different coordinate system.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Igon83
  • 21
  • 4
  • Is it even possible to transform to a `CGImage` directly? If you're talking about transforming it when drawing in a `CGContext`, look at the documentation on `CGContextGetUserSpaceToDeviceSpaceTransform`. You can apply the transform returned by this function to that of the UIImageView. Then, apply the resulting combined transform to the context you're drawing your image in. – Alexei Sholik Apr 08 '11 at 17:13

1 Answers1

1

The steps you have to take are:

  1. Create a new graphics context
  2. Apply the transforms from the UIImageView to the context
  3. Draw your original image into the context
  4. Extract a new image from the context

Things you have to watch out for are the inverted co-ordinate system and the fact that the rotated image's bounding rectangle is now larger than the it originally was and you have to take this into account when creating your context.

See my earlier post: Creating a UIImage from a rotated UIImageView

Community
  • 1
  • 1
Magic Bullet Dave
  • 9,006
  • 10
  • 51
  • 81