我在使用 UIImagePickerController 时遇到了一点问题......我想使用用户从 iPhone 库中选择的图像,并在实例化我的 viewController 时使用它:
首先,用户必须单击 StartWithImage 按钮:
-(IBAction)startWithImage:(UIButton *) sender
{
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:self.imgPicker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
[imagePicker release];
//UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
photo =(UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
//code for starting game
}
这就是我实例化我的 viewController 的方式:
imageSliderViewController = [[ImageSliderViewController alloc] initWithSize:colMax :rowMax:photo];
我的视图控制器在 viewDidLoad 中使用照片,如下所示:
CGImageRef cgImg = CGImageCreateWithImageInRect(photo.CGImage, CGRectMake(ox, oy, width-1, height-1));//-1 for block effect
我收到 EXC_BAD_ACCESS 错误...