This is probably not as hard as I think it is, but how can I select part of an image? Consider the following example:
The grey area is an image in the PNG or JPG Format, now I want to select the red 80x80 px area from it. The red area should be displayed, the rest not. I have tried numerous approaches:
I also had a look at the drawing functions, yet I have not worked with these yet and it seemed a little bit far fetched to me. Is there any obvious way for doing what I want to do that I am missing out on? I do not want the image to be resized, just clipped.
Thanks for your time!
Stole the code below from this question and look for HitScan's answer.
CGImageRef imageRef = CGImageCreateWithImageInRect([largeImage CGImage], cropRect);
// or use the UIImage wherever you like
[UIImageView setImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);
If you only want to show the center of the image an a UIImageView
set the content mode to "Aspect Fill" via IB. That will center it and crop off anything extra.
Or in code
myImageView.contentMode = UIViewContentModeScaleAspectFill;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With