gpt4 book ai didi

ios - 如何从 ALAsset 对象获取全景图

转载 作者:可可西里 更新时间:2023-11-01 06:07:26 26 4
gpt4 key购买 nike

我们有大约 2k 个对象,它们是类 ALAsset 的实例,我们需要知道哪些文件是全景图像。我们尝试从 ALAsset 实例中获取 CGImageRef 并检查宽度/高度比。

ALAsset *alasset = ...
CFImageRef = alasset.thumbnail; // return square thumbnail and not suitable for me
CFImageRef = alasset.aspectRationThumbnail; //return aspect ration thumbnail, but very slowly

它不适合我们,因为它对许多文件运行缓慢。

我们还尝试从 defaultRepresentation 获取元数据并检查图像 EXIF,但速度很慢。

NSDictionary *dictionary = [alasset defaultRepresentation] metadata]; //very slowly to

有什么办法可以让它变得更好吗?

谢谢

最佳答案

最后,我为 ALAsset 找到了这个解决方案:

ALAssetsLibrary *assetsLibrary = ...;
NSOperation *queue = [NSoperationQueue alloc] init];
static NSString * const kAssetQueueName = ...;
static NSUInteger const kAssetConcurrentOperationCount = ...; //I use 5
queue.maxConcurrentOperationCount = kAssetConcurrentOperationCount;
queue.name = kAssetQueueName;
dispatch_async(dispatch_get_main_queue(), ^{
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
/*You must check the group is not nil */
if (!group)
return;
/*Then you need to select group where you will search panoramas: for iPhone-Simulator it's @"Saved Photos" and "Camera Roll" for iPhone. It's actuality only for iOS 7 or early. */
static NSString * const kAssetGroupName = ...;
if ([[group valueForProperty:ALAssetsGroupPropertyName] kAssetGroupName]) {
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) {
if (!asset)
return;
[queue addOperationWithBlock:^{
//I use @autoreleasepool for instant memory release, after I find panoramas asset url
@autoreleasepool {
ALAssetRepresentation *defaultRepresentation = asset.defaultRepresentation;
if ([defaultRepresentation.UTI isEqualToString:@"public.jpeg"]) {
NSDictionary *metadata = defaultRepresentation.metadata;
if (!metadata)
return;
if (metadata[@"PixelWidth"] && metadata[@"PixelHeight"]) {
NSInteger pixelWidth = [metadata[@"PixelWidth"] integerValue];
NSInteger pixelHeight = [metadata[@"PixelHeight"] integerValue];
static NSUInteger const kSidesRelationshipConstant = ...; //I use 2
static NSUInteger const kMinimalPanoramaHeight = ...; //I use 600

if (pixelHeight >= kMinimalPanoramaHeight && pixelWidth/pixelHeight >= kSidesRelationshipConstant) {/*So, that is panorama.*/}
}

}];

}];
}
} failureBlock:^(NSError *error) {
//Some failing action, you know.
}];
};

也就是说。所以,我认为这不是最好的解决方案。然而,就今天而言,我还没有找到更好的方法。

关于ios - 如何从 ALAsset 对象获取全景图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24510857/

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