gpt4 book ai didi

objective-c - 选取的图像 xcode 的名称

转载 作者:行者123 更新时间:2023-12-01 17:42:58 26 4
gpt4 key购买 nike

我想获取从库中挑选或新点击的图像的名称 -

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

我正在使用这段代码:
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
AppDelegate *del = [[UIApplication sharedApplication]delegate];
[self dismissModalViewControllerAnimated:YES];
image = [info objectForKey:UIImagePickerControllerOriginalImage];

NSLog(@"imagekbgfg=====>%@",image);
[self.imageView setImage:image];

imgName = [info objectForKey:UIImagePickerControllerOriginalImage];

del.mainImgName = imgName;
del.imageData = UIImageJPEGRepresentation(image, 1.0);
del.imageApp = image;
}

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
}

我怎样才能做到这一点?

最佳答案

使用下面的代码,您将获得如下路径:assets-library://asset/asset.JPG?id=79450962-C0FD-484C-808B-83E045F40972&ext=JPG当您从相册中挑选图像时。此路径有效。它包含 Assets ID 和 Assets 类型。

// Firstly get the picked image's file URL.
NSURL *imageFileURL = [info objectForKey:UIImagePickerControllerReferenceURL];

// Then get the file name.
NSString *imageName = [imageFileURL lastPathComponent];
NSLog(@"image name is %@", imageName);

如果您想使用 UIImagePickerController 获得的路径再次选择图像用户.(这里也许你想保存路径,这样你就可以读回那个图像而不要求用户再次选择那个图像)你需要 ALAssetsLibrary否则你不需要它。
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
__block UIImage *returnValue = nil;
[library assetForURL:imageFileURL resultBlock:^(ALAsset *asset) {
returnValue = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
} failureBlock:^(NSError *error) {
NSLog(@"error : %@", error);
}];

关于objective-c - 选取的图像 xcode 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13512260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com