Cropping an UIImage

后端 未结 24 1807
轮回少年
轮回少年 2020-11-22 02:45

I\'ve got some code that resizes an image so I can get a scaled chunk of the center of the image - I use this to take a UIImage and return a small, square repre

24条回答
  •  孤独总比滥情好
    2020-11-22 03:26

    Follow Answer of @Arne. I Just fixing to Category function. put it in Category of UIImage.

    -(UIImage*)cropImage:(CGRect)rect{
    
        UIGraphicsBeginImageContextWithOptions(rect.size, false, [self scale]);
        [self drawAtPoint:CGPointMake(-rect.origin.x, -rect.origin.y)];
        UIImage* cropped_image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return cropped_image;
    }
    

提交回复
热议问题