I want to pick an image and then crop to a circle. Cropping to a square is easy enough. I put:
Code:
self.imagePicker.allowsEditing = YES;
under viewDidLoad.
and then
Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if (picker == imagePicker) {
// set your obverse image
// Delete any existing image.
NSManagedObject *oldImage = recipe.image;
if (oldImage != nil) {
[recipe.managedObjectContext deleteObject:oldImage];
}
// Create an image object for the new image.
NSManagedObject *obverse = [NSEntityDescription insertNewObjectForEntityForName:@"Image" inManagedObjectContext:recipe.managedObjectContext];
recipe.image = obverse;
// Set the image for the image managed object.
//UIImage *selectedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
UIImage *selectedImage = [info objectForKey:@"UIImagePickerControllerEditedImage"];
[recipe.image setValue:selectedImage forKey:@"obverse"];
// Create a thumbnail version of the image for the recipe object.
CGSize size = selectedImage.size;
CGFloat ratio = 0;
if (size.width > size.height) {
ratio = 320.0 / size.width;
} else {
ratio = 320.0 / size.height;
}
CGRect rect = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height);
UIGraphicsBeginImageContext(rect.size);
[selectedImage drawInRect:rect];
recipe.thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
}
This allows me to crop my image to a square that is 320x320.
Anyone know how to change it so that the image is cropped to a circle that is 320 wide?