Igon83
Igon83

Reputation: 21

Quartz 2D: how apply UIImageView transformation to a CGImage?

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.

Upvotes: 1

Views: 1395

Answers (1)

Magic Bullet Dave
Magic Bullet Dave

Reputation: 9076

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

Upvotes: 1

Related Questions