我目前正在开发一个项目,我使用相机点击图像或让用户从图片库中选择它并在uiimageview上设置图像。当用户从图片库中选择图片时,我成功获取图片名称,但当用户点击app.how中的相机来实现图像名称时,无法获取图片名称?我必须使用网络服务发送带有图像名称的图像。
答案 0 :(得分:0)
在imagePicker委托方法中:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage];
if (chosenImage == nil) {
chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];
}
NSData *webData = UIImagePNGRepresentation(chosenImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"myphoto.png"];
[webData writeToFile:localFilePath atomically:YES];
chosenImage = [UIImage imageWithContentsOfFile:localFilePath];
}
localFilePath
将是您的图片名称。希望这会对你有所帮助。