Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-19-2010, 11:45 AM   #1 (permalink)
krye
Registered Member
 
krye's Avatar
 
Join Date: Jan 2009
Location: NY, USA
Posts: 357
Default Image Picker: then crop image to circle?

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?
krye is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,857
Threads: 89,223
Posts: 380,681
Top Poster: BrianSlick (7,129)
Welcome to our newest member, Donovan472
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:21 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.