0

Given a UIImageView, and a CGRect inside that UIImageView, how do I get a sub-UIImage of the UIImage displayed in the UIImageView that is a cut-out of the image matching the CGRect?

I’m struggling to get a solution for this problem when the size of the image and image view do not match, and the contentMode is any arbitrary built-in value.

When the size of the image and the imageView are exactly the same, then one can use CGImageCreateWithImageInRect() with the CGRect to do this. But if they’re different, then how can I do this?

I already tried using UIGraphicsBeginImageContextWithOptions() and renderInContext: as described here, and it was off-course.

2
  • Please provide enough code so others can better understand or reproduce the problem. Commented Oct 22, 2024 at 20:12
  • Perhaps something like stackoverflow.com/a/63784185/1271826. I only handle a few common content modes, but the idea is to just convert the rect of within the image view to the appropriate rect within the image. Commented Oct 23, 2024 at 0:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.