UIImage cropping on user selected rectangle in iphone?
- by Rajendra Bhole
Hi,
I developing an small application in which i want to crop the UIImage captured by imagePickerControllerSourceTypeOfCamera.
The UIImage should crop by user selected crop area or cropped rectangle.
That means first user capture the image from the camera.Then on captured image the user selected an rectangle having color gray.That image(image data) should crop from that gray colored rectangle.
My under develop code is as follows.
-(IBAction) getPhoto:(id)sender
{
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
if((UIButton *) sender == btnphotoAlbum)
{
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else
{
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
}
imagePickerController.allowsImageEditing = YES;
//imagePickerController.toolbar.barStyle =UIBarStyleBlackOpaque;
//UIToolbar *toolBar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 20, 320)];
//imagePickerController.
[self presentModalViewController:imagePickerController animated:YES];
}
(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
UIImage *selectedImage = image;
UIImage *originalImage = [editingInfo objectForKey:@"UIImagePickerControllerOriginalImage"];
NSValue *cropRect = [editingInfo
objectForKey:UIImagePickerControllerCropRect];
CGRect theRect = [cropRect CGRectValue];
//captureImage.image =[info objectForKey:@"UIImagePickerControllerOriginalImage"];
[picker dismissModalViewControllerAnimated:YES];
}
How i crop the image?