How to crop the image in objective c?

前端 未结 2 1315
长发绾君心
长发绾君心 2020-12-09 05:58

The user can change the cropbox size which is shows default in edit screen. I tried with below code :

- (UIImage *)imageByCropping:(UIImage *)imageToCrop toR         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 06:50

    For Get Crop Image:

    UIImage *croppedImg = nil;
    CGRect cropRect = CGRectMake("AS YOu Need"); //set your rect size.
    croppedImg = [self croppIngimageByImageName:self.imageView.image toRect:cropRect];
    

    Use following code for call croppIngimageByImageName:toRect: method that return UIImage (with specific size of image)

    - (UIImage *)croppIngimageByImageName:(UIImage *)imageToCrop toRect:(CGRect)rect
        {
            //CGRect CropRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height+15);
    
            CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
            UIImage *cropped = [UIImage imageWithCGImage:imageRef];
            CGImageRelease(imageRef);
    
            return cropped;
        }
    

提交回复
热议问题