gpt4 book ai didi

ios - 使用 ALAssetLibrary 获取照片库中图像的时间戳

转载 作者:行者123 更新时间:2023-11-29 03:21:38 25 4
gpt4 key购买 nike

我正在尝试显示照片库中的图像以及时间戳(创建或修改时间)。我使用以下代码获取了图像。我怎样才能正确得到他们的时间戳?这是代码:

-(void)getAllPictures{
imageArray=[[NSArray alloc] init];
mutableArray =[[NSMutableArray alloc]init];
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];

library = [[ALAssetsLibrary alloc] init];

void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != nil) {
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
[assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];

NSURL *url= (NSURL*) [[result defaultRepresentation]url];

[library assetForURL:url
resultBlock:^(ALAsset *asset) {
[mutableArray addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];

if ([mutableArray count]==count)
{
imageArray=[[NSArray alloc] initWithArray:mutableArray];
[self allPhotosCollected:imageArray];
}
}
failureBlock:^(NSError *error){ NSLog(@"operation was not successfull!"); } ];
NSLog(@"ali: %@",result);

}
}
};

NSMutableArray *assetGroups = [[NSMutableArray alloc] init];

void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
[assetGroups addObject:group];
count=[group numberOfAssets];
}
};

assetGroups = [[NSMutableArray alloc] init];

[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {NSLog(@"There is an error");}];}
-(void)allPhotosCollected:(NSArray*)imgArray{
//write your code here after getting all the photos from library...
NSLog(@"all pictures are %@",imgArray);
for (int i=0; i<imgArray.count; i++) {


UIImageView *img=[[UIImageView alloc] initWithImage:imgArray[i]];
img.frame=CGRectMake(10, 20+105*i, 200, 100);
[self.view addSubview:img];

}

最佳答案

要获取时间戳,请使用:

 NSDate *date =  [asset valueForProperty:ALAssetPropertyDate];

关于ios - 使用 ALAssetLibrary 获取照片库中图像的时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21020254/

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