0

I am using the Allowsedditing to crop the photo that I took in the app but it does not work since it bounces back. Is there away to do this task? I was told that I should use the GKIIMagePicker but it does not work. How should I do this?

- (IBAction)takePhoto:(UIButton *)sender {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    self.imagePicker = [[GKImagePicker alloc] init];
    self.imagePicker.cropSize = CGSizeMake(320, 90);
    self.imagePicker.delegate = self;
    self.imagePicker.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentModalViewController:self.imagePicker.imagePickerController animated:YES];

}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2590480
  • 149
  • 1
  • 9

1 Answers1

0

Here this works:

UIImage *image = [UIImage imageNamed:@"myImage"];
NSData *data = UIImageJPEGRepresentation(image, 1.0);

//reduce size of image (scale down)
UIImage *image2 = [UIImage imageWithData:data scale:2.0];
//increase size of image (scale up)
UIImage *image3 = [UIImage imageWithData:data scale:0.5];

Specify your own CGFloat value as scale to crop.

iphondroid
  • 498
  • 7
  • 19
  • I don't get this code at all. It looks helpfull but where am I suppose to put this. Ill update my question with current codes.I am an objective-c beginner – user2590480 Jul 25 '13 at 14:53
  • @user2590480 - You drag an image named "myImage" in your project and drag an `UIImageView` to your .xib file. Then write this code in `-(void) viewDidLoad{ }` and finally add line of code to set the image -- `[imageView setImage:image2];` where `imageView` is your `UIImageView`. – iphondroid Jul 25 '13 at 14:57
  • 1
    NONONO!!! I want to crop an image that I took in the app(a camera button that I took in my app and then want to just crop it and save ! – user2590480 Jul 25 '13 at 15:00
  • no problem are you able to set the image taken from camera into an imageView? – iphondroid Jul 25 '13 at 15:04
  • sorry my first approach was to use the allowsediting however it did not work since it did not crop, the second approach was to use the GTIImagePicker but it did not work. I wanted to take a picture and then just move on to the cropping so that it will become square. I have little knowledge about imageView however I cannot display it to another view controllers image view saying that I have two view controllers and I take it in one view controller and show it on the second however I cannot do that.... – user2590480 Jul 25 '13 at 15:08
  • Here check this link for taking a photo and saving it http://stackoverflow.com/questions/6812634/how-to-take-picture-from-camera-saved-in-photo-gallery-by-programmatically Here just add my last 3 lines of code before you save the photo if([mediaType isEqualToString:(NSString*)kUTTypeImage]) { UIImage *photoTaken = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; //MY CODE HERE //Save Photo to library only if it wasnt already saved i.e. its just been taken if (picker.sourceType == UIImageP..... – iphondroid Jul 25 '13 at 15:13
  • Do I have to save it? since I want to save it after cropping it.? Is there away that I can't pass the photo or anything? – user2590480 Jul 25 '13 at 15:23