0

我在使用 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 错误...

4

1 回答 1

0

好吧,EXC_BAD_ACCESS 通常发生在对象被释放并且我们在某个地方尝试访问该对象时。

尝试这个

- (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{

    //UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    photo =(UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
    //code for starting game

    // dismiss controller after working with it
    [self dismissModalViewControllerAnimated:YES];
    [imagePicker release];
}
于 2013-11-06T13:24:49.570 回答