How to use move and resize UIImagePickerController in iPhone?

advertisements

I am new to iPhone development. I am working with image picker controller in which I want to move and scale the image that picked from the photo library, so I enabled the allowsediting = yes.

And my picker did finish method:

 - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Access the uncropped image from info dictionary

    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    self.imgForDisplay.image=[self scaleAndRotateImage:image];
    self.imagePicker.allowsEditing = YES;

    ImageDetailsViewController *imageDetailsVC = [[ImageDetailsViewController alloc] init];
    imageDetailsVC.imagedisplay.image = self.imgForDisplay.image;
    [picker pushViewController:imageDetailsVC animated:YES];

//[picker dismissModalViewControllerAnimated:YES];

}

and I push another view controller where I want to show the Image picked.

Here I have two problems:

1) When I select the image, its navigating to another view without "move and scaling" screen but the image is now displayed in the ImageDetailsViewController when it navigates.

2) When I again navigate back and pick another image, now it shows the "move and scaling" screen. When I click the choose button, it is simply showing a white screen with out navigation bar.

Is there any way to set the action for the choose button?


I too face the same problem i solved it by using the by using the code, go through this it will be usefull.

 - (void)imagePickerController:(UIImagePickerController *)picker
    didFinishPickingMediaWithInfo:(NSDictionary *)info {
        self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerMediaType];
        if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) {
            UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage];
            UIImage *shrunkenImage = shrinkImage(chosenImage, imageFrame.size);
            self.image = shrunkenImage;
        } else if ([lastChosenMediaType isEqual:(NSString *)kUTTypeMovie]) {
            self.movieURL = [info objectForKey:UIImagePickerControllerMediaURL];
        } 

        ImageSelectionView *imageSelectionVC = [[ImageSelectionView alloc] init];
        imageSelectionVC.theImage = image;
        [picker pushViewController:imageSelectionVC animated:YES];
        imageSelectionVC.dismissDelegate =self;

       // [picker dismissModalViewControllerAnimated:YES];
    }

'

-(void)updateDisplay {
    if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) {
        imageView.image = image;
        imageView.hidden = NO;
        moviePlayerController.view.hidden = YES;
    } else if ([lastChosenMediaType isEqual:(NSString *)kUTTypeMovie]) {
        [self.moviePlayerController.view removeFromSuperview];
        self.moviePlayerController = [[MPMoviePlayerController alloc]
                                       initWithContentURL:movieURL] ;
        moviePlayerController.view.frame = imageFrame;
        moviePlayerController.view.clipsToBounds = YES;
        [self.view addSubview:moviePlayerController.view];
        imageView.hidden = YES;
    }
}