Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate and Crop UIImage

Imagine I have an UIImage. I need to rotate and then crop it in the global coordinate system (not UIImage coordinate system). So the resulted image will be cropped and rotated.

How can I do this? CGImageCreateWithImageInRect will crop image only in the image-relative coordinates.

enter image description here

PS Answer in comments. You should use CIImage.

like image 481
gleb.kudr Avatar asked Oct 31 '22 17:10

gleb.kudr


1 Answers

Maybe this can help

//init
CIImage *image = [CIImage imageWithCGImage:CGImageRef];
//rotation
CIImage *rotatedImage = [image imageByApplyingTransform:someTransform];
//crop
CIImage *croppedImage = [rotatedImage imageByCroppingToRect:someRect];
like image 120
dopcn Avatar answered Nov 15 '22 07:11

dopcn