priyanka gautam
priyanka gautam

Reputation: 377

Cropping Option For Image

I want to choose picture from album and taking by Camera. It code work well but I need to select only part of image means cropping of image set my imageView.

-(IBAction)chooseAlbum:(id)sender
{
    imagePicker=[[UIImagePickerController alloc]init];
    imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.delegate=self;
    [self presentViewController:imagePicker animated:YES completion:nil];
}

-(IBAction)takePicture:(id)sender
{
    imagePicker=[[UIImagePickerController alloc]init];
    imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
    imagePicker.delegate = self;

    [self presentViewController:imagePicker animated:YES completion:nil];
}

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
     profileImageView.image=[info objectForKey:UIImagePickerControllerOriginalImage];

    [self dismissViewControllerAnimated:YES completion:nil];
}

Upvotes: 2

Views: 105

Answers (3)

yankit Patel
yankit Patel

Reputation: 331

you have to just add property imagePicker.

imagePicker.allowsEditing = YES;

Upvotes: 1

Akshay Agrawal
Akshay Agrawal

Reputation: 217

However you can also use the following third party library if you want more control and pleasant effect/animation.
https://github.com/myang-git/iOS-Image-Crop-View

Upvotes: 0

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 40018

Turn on the editing mode

imagePicker.allowsEditing = YES;

Then in your delegate method use UIImagePickerControllerEditedImage key

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {
    profileImageView.image=[info objectForKey:UIImagePickerControllerEditedImage];
    [self dismissViewControllerAnimated:YES completion:nil];
}

Upvotes: 2

Related Questions