使用UIImagePickerController从iPhone照片库或照相机获取图像

if ([buttonTitle isEqualToString:@"拍照"])

    {

        UIImagePickerController *imgPicker = [UIImagePickerController new];

        imgPicker.delegate = self;

        imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        [self presentModalViewController:imgPicker animated:YES];

    }

    else if([buttonTitle isEqualToString:@"图库"])

    {

        UIImagePickerController *imgPicker = [UIImagePickerController new];

        imgPicker.delegate = self;

        imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentModalViewController:imgPicker animated:YES];

    }

//用户选中图片后的回调

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

    [self dismissModalViewControllerAnimated:YES];

    //添加到集合中

    UIImage * imgData = [info objectForKey:UIImagePickerControllerOriginalImage];

    self.img.image = [Tool scale:imgData toSize:[Tool scaleSize:imgData.size]];

    [Config Instance].tweetCachePic = [Tool scale:imgData toSize:[Tool scaleSize:imgData.size]];

    [self clickBackground:nil];

}

//用户取消选择某张图片

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

    [self dismissModalViewControllerAnimated:YES];

}

你可能感兴趣的:(使用UIImagePickerController从iPhone照片库或照相机获取图像)