如何从Photolibrary图像获取拇指图像? [英] How to get thumb image from Photolibrary image?

查看:127
本文介绍了如何从Photolibrary图像获取拇指图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在获取内存问题,因为我在React Native的Flatlist中加载直接图像。问题在于,由于高分辨率图像达到内存限制并且应用程序在iPhone上崩溃。有什么方法我可以像图像网址一样获取直接的拇指网址(例如url:'assets-library://asset/asset.JPG?id = 5BECA80C-33B3-46A0-AE44-CF28A838CECF& ext = JPG',)?

Currently i am fetching memory issue because i am loading direct image in Flatlist of React Native. Issue is that due to high resolutions images memory limit reached and app get crashed on iPhone. Is there any way i can fetch direct thumb url like image url (e.g. url: 'assets-library://asset/asset.JPG?id=5BECA80C-33B3-46A0-AE44-CF28A838CECF&ext=JPG',) ?

目前我正在使用'React-native-photo-framework'。

Currently i am using 'React-native-photo-framework'.

推荐答案

最后,我有自己的解决方案来解决这个问题。我已经尝试了各种方法来解决,但我无法解决它。最后,我开始知道新的Photo Library提供了获取已调整大小的图像的选项,但那不能用于反应,本机照片框架。我的本土经验将帮助我解决我的问题,希望这对您有所帮助。 此处链接详细说明和代码。

Finally i have my own solution for this question. I have tried all ways to resolve but i am not able to resolve it. Lastly i come to know that new Photo Library provide options to fetch resized image but thats what not working with react-native-photos-framework. My native experience will help me to resolve my issue, hope this will help you. Here is link with detail description and code.

让我在这里添加代码片段。

Let me add here code snippets.

导入本机照片库

#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];

}];

这篇关于如何从Photolibrary图像获取拇指图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆