簡體   English   中英

使用UIImagePickerController檢索照片庫中的選定圖像

[英]Using UIImagePickerController to retrieve selected Image in photo Library

我在使用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錯誤...

好吧,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];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM