【发布时间】:2014-11-25 23:01:38
【问题描述】:
我有一个 UIImageView 加载用户的个人资料图片。我添加了一些 UIImagePicker 功能,现在用户可以通过使用相机或从库中添加来更改个人资料图片。这是代码:
- (IBAction)cameraAction:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)libraryAction:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
_profilePhoto.image = chosenImage;
UIImageWriteToSavedPhotosAlbum(_profilePhoto.image, nil, nil, nil);
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
现在,我有 php 文件将当前图像上传到服务器。问题是,php 的输入参数是图像文件名。我确实环顾了很多次,知道要获取图像名称,首先我需要将其保存到应用程序文档目录,然后用我想要的名称重命名它。所以谁能告诉我如何将这张图片保存到应用程序文档目录,如何获取它以及如何用我想要的那个重命名它。提前致谢
【问题讨论】:
标签: ios objective-c uiimage uiimagepickercontroller document