目前,我正在获取内存问题,因为我正在加载直接图像中的反应本机的Flatlist。问题是,由于高分辨率的图像内存限制,应用程序在iPhone上崩溃。有什么方法可以直接获取像图像url这样的拇指url (例如url:'assets-library://asset/asset.JPG?id=5BECA80C-33B3-46A0-AE44-CF28A838CECF&ext=JPG',)?
目前,我正在使用‘反应-本机-照片-框架’。
发布于 2018-05-26 14:21:51
最后,我对这个问题有了自己的解决办法。我试过各种方法来解决这个问题,但我无法解决。最后,我了解到新的照片库提供了获取大小调整的图像的选项,但这并不适用于反应-本机-照片.框架。我的本土经验将帮助我解决我的问题,希望这将有助于你。这里是与详细描述和代码的链接。
让我在这里添加代码片段。
导入本地照片库
#import <Photos/Photos.h>
CGSize retinaSquare = CGSizeMake(600, 600);
PHImageRequestOptions *cropToSquare = [[PHImageRequestOptions alloc] init];
cropToSquare.resizeMode = PHImageRequestOptionsResizeModeExact;
cropToSquare.deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic;
[cropToSquare setSynchronous:YES];
NSURL *imageurl = [NSURL URLWithString:@"youimagepath"];
PHFetchResult* asset =[PHAsset fetchAssetsWithALAssetURLs:[NSArray arrayWithObjects:imageurl, nil] options:nil];
[[PHImageManager defaultManager] requestImageForAsset:(PHAsset *)[asset objectAtIndex:0] targetSize:retinaSquare contentMode:PHImageContentModeAspectFit options:cropToSquare resultHandler:^(UIImage *fetchedImage, NSDictionary *info) {
NSData *imageData = UIImageJPEGRepresentation(fetchedImage,0.65);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%0.0f.jpg", timeStamp*1000]];
NSError *error = nil;
[imageData writeToFile:filePath options:NSDataWritingAtomic error:&error];
NSURL* fileUrl = [NSURL fileURLWithPath:filePath];
if(error){
fileUrl = imageurl;
}
NSString *resizedImagePath = [NSString stringWithFormat:@"%@",fileUrl];
}];
发布于 2018-04-01 16:07:22
getAssets
拿了一个prepareForSizeDisplay
道具。这使用PHCachingImageManager
请求指定大小的资产映像。
示例:
RNPhotosFramework.getAssets({
startIndex: 0,
endIndex: 100,
prepareForSizeDisplay: Rect(100,100),
fetchOptions: {
sourceTypes: ['userLibrary'],
sortDescriptors: [{
key: 'creationDate',
ascending: true,
}]
}
}).then((response) => console.log(response.assets));
当用户点击FlatList
中的行时,您可以获取完整的资产。除非您需要显示,否则不要获取完整的资产。
https://stackoverflow.com/questions/49305438
复制相似问题