0

以下是我用于从源获取图像然后裁剪它的代码

这就是我选择源目的地的方式

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //Get the name of the current pressed button
    NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];


    if ([buttonTitle isEqualToString:@"Camera Library"]) {
        [self performSelector:@selector(pickImage:) ];
    }
    if ([buttonTitle isEqualToString:@"Camera"]) {
        [self performSelector:@selector(startcamera:) ];
    }
    if ([buttonTitle isEqualToString:@"Cancel"]) {
        NSLog(@"Cancel pressed --> Cancel ActionSheet");
    }

}



- (IBAction) pickImage:(id)sender
{

    if([UIImagePickerController isSourceTypeAvailable:
        UIImagePickerControllerSourceTypePhotoLibrary])
    {
        UIImagePickerController *picker= [[UIImagePickerController alloc]init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }




}
- (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.imagee = shrunkenImage;
        selectImage.image = imagee;
    }     
    [picker dismissModalViewControllerAnimated:YES];
}




-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
    [picker dismissModalViewControllerAnimated:YES];
}


#pragma mark  -
static UIImage *shrinkImage(UIImage *original, CGSize size) {
    CGFloat scale = [UIScreen mainScreen].scale;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGContextRef context = CGBitmapContextCreate(NULL, size.width * scale,
                                                 size.height * scale, 8, 0, colorSpace, kCGImageAlphaPremultipliedFirst);
    CGContextDrawImage(context,
                       CGRectMake(0, 0, size.width * scale, size.height * scale),
                       original.CGImage);
    CGImageRef shrunken = CGBitmapContextCreateImage(context);
    UIImage *final = [UIImage imageWithCGImage:shrunken];

    CGContextRelease(context);
    CGImageRelease(shrunken);   

    return final;
}

- (void)updateDisplay {
    if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) {
        imageView.image = imagee;
        imageView.hidden = NO;

    } 
}


- (IBAction) startcamera:(id)sender
{


    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {

        UIImagePickerController *picker = [[[UIImagePickerController alloc]init]autorelease];
        picker.delegate = self;
        picker.sourceType =  UIImagePickerControllerSourceTypeCamera;

        picker.allowsEditing=NO;

        [self presentModalViewController: picker animated:YES];


    }else {
        UIAlertView *alt = [[UIAlertView alloc] 
                            initWithTitle:@"Error" 
                            message:@"Camera Image Source Not Available" 
                            delegate:nil cancelButtonTitle:@"OK" 
                            otherButtonTitles:nil];
        [alt show];
        [alt release];
    }
}

updateDisplay 这个方法是在viewDidAppear 中调用的。

now my problem is image picker view gets open i see the library images but when select then it get dismiss its not going in crop image screen yes i have used mobileCoreService framework

4

1 回答 1

2

用这个

-(void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo 
{
 UIImage *shrunkenImage = shrinkImage(image, imageFrame.size);
        self.imagee = shrunkenImage;
        selectImage.image = imagee;
    }     
    [picker dismissModalViewControllerAnimated:YES];
}
于 2013-04-15T06:52:46.387 回答