Dara Tith
Dara Tith

Reputation: 528

Objective-C Cropping Image by Drawing

I am new in iOS. I want to crop the image by drawing from user. I search on google for one day and i didn't get the result. Thank you for your answer.

Upvotes: 4

Views: 1391

Answers (2)

Mutech Dev01
Mutech Dev01

Reputation: 446

- (UIImage *)crop:(CGRect)rect {

    rect = CGRectMake(rect.origin.x*self.scale, 
                      rect.origin.y*self.scale, 
                      rect.size.width*self.scale, 
                      rect.size.height*self.scale);       

    CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], rect);
    UIImage *result = [UIImage imageWithCGImage:imageRef 
                                          scale:self.scale 
                                    orientation:self.imageOrientation]; 
    CGImageRelease(imageRef);
    return result;
}

Upvotes: 0

Jugal K Balara
Jugal K Balara

Reputation: 927

Try this code

  UIImagePickerController *picker=[[UIImagePickerController alloc] init];
    picker.delegate = self;
    [picker setAllowsEditing:YES];
    picker.sourceType=UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:nil];

Then you can get cropping image from

  - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
 {
  UIImage *image = [info valueForKey:UIImagePickerControllerEditedImage];
 picker dismissViewControllerAnimated:YES completion:^{}];

}

Upvotes: 1

Related Questions