- (IBAction)chooseImgBtnClick:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
_image=[info objectForKey:UIImagePickerControllerOriginalImage];
[_vehicleImageView setImage:_image];
[self dismissViewControllerAnimated:YES completion:NULL];_vehicleImageView.image= [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *webData = UIImagePNGRepresentation(_vehicleImageView.image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"png"];
[webData writeToFile:localFilePath atomically:YES];
NSLog(@"localFilePath.%@",localFilePath);
_filePath=localFilePath;
}
影像使用我选择从库中的照片,上面的代码,并设置在UIImageView的照片并试图采取的路径到一个名为localFilePath字符串。我将路径分配给_filepath。加载图像到ImageView的,采取从文件路径
现在我编写了一个函数,用于从文件路径中获取图像,并在单击另一个按钮时将图像载入另一个UIImageView。 但图像没有被加载。请告知
以下是功能。
- (IBAction)loadSecondView:(id)sender {
NSData *pngData = [NSData dataWithContentsOfFile:_filePath];
UIImage *image = [UIImage imageWithData:pngData];
[_secondImageView setImage:image];
}
只有三个sourceTypes可用,其中一个是相机。除非你想要相机胶卷(sourceType == savedPhotosAlbum),否则很难知道你正在寻找什么,没有一个更详细的例子。 iOS设备上的“任何目录”要么不明确(你的意思是iCloud还是其他地方的“off-device”?)或不可能的(iOS设备没有目录概念)。请给予更多的细节.... – dfd
我同意@dfd。请阅读这里的答案: - http://stackoverflow.com/a/1082265/4525734 此外,这是链接到苹果文档: https://developer.apple.com/reference/uikit/uiimagepickercontrollersourcetype –
是不可能从文档文件夹中选择图像或者在项目中创建的具有一些图像的任何文件夹? – Harish