使用UIImagePickerController從iPhone照片庫或照相機獲取圖像

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

    { 圖片

        UIImagePickerController *imgPicker = [UIImagePickerController new]; it

        imgPicker.delegate = self; io

        imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera; cli

        [self presentModalViewController:imgPicker animated:YES]; object

    } im

    else if([buttonTitle isEqualToString:@"圖庫"]) img

    { 集合

        UIImagePickerController *imgPicker = [UIImagePickerController new]; animate

        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];

}

相關文章
相關標籤/搜索