phasset

How to access NSData/NSURL of slow motion videos using PhotoKit

三世轮回 提交于 2019-11-29 00:10:52
Working with new Photo framework, I can access the NSData of PHAssets using requestImageDataForAsset . I can also access the file URL using the PHImageFileURLKey of the returned info NSDictionary . [[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) { //imageData contains the correct data for images and videos NSLog(@"info - %@", info); NSURL* fileURL = [info objectForKey:@"PHImageFileURLKey"]; }]; This works fine for images and normal videos. However, when the

How to fetch images from photo library within range of two dates in iOS?

荒凉一梦 提交于 2019-11-28 13:08:16
Context I am try to fetch images within range of two dates from the photo library. Firstly, I am getting info of the photo library images one by one in the dictionary form and picking every image date by using key and comparing that date with two dates by using if condition. If that image's date lies between the two dates, I insert that image into array. I am Saving images in array because I would like to show them in a collection view. Problem While it is working on simulator, it is not working on real device because of memory issues. I think there are bunch of images in the real device photo

PHAsset to UIImage

走远了吗. 提交于 2019-11-28 04:38:32
I'm attempting to create a UIImage (like a thumbnail or something) from a PHAsset so that I can pass it into something that takes a UIImage. I've tried adapting solutions I found on SO (since they all just directly pass it into say a tableview or something), but I have no success (likely because I'm not doing it right). func getAssetThumbnail(asset: PHAsset) -> UIImage { var retimage = UIImage() println(retimage) let manager = PHImageManager.defaultManager() manager.requestImageForAsset(asset, targetSize: CGSize(width: 100.0, height: 100.0), contentMode: .AspectFit, options: nil, resultHandler

How to get URL for a PHAsset? [duplicate]

别说谁变了你拦得住时间么 提交于 2019-11-27 23:10:54
This question already has an answer here: How to get an ALAsset URL from a PHAsset? 4 answers I am using a third party library to select multiple images from the Photo Library. On selecting multiple images it returns an array of PHAsset objects. Now, I want to save the URL (or some reference) for these objects in the core data. But I do not know how to get the URL. Is there any other reference I could store in the core data which could help me in fetching the same image from the photo library? diegomen I used @iMHitesh Surani answer and it worked perfect, I converted it into Swift 3.1 and put

How to fetch all images from custom Photo Album - swift

一笑奈何 提交于 2019-11-27 21:40:01
How to fetch all images from custom Photo Album? var fetchOptions = PHFetchOptions() fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: false)] fetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.Image.rawValue) let allImages:PHFetchResult = PHAsset.fetchKeyAssetsInAssetCollection(albumList[index].collection, options: fetchOptions) This code block is fetching just few of them. Thanks. -> albumList[index].collection 's type is PHAssetCollection For Swift 4 using this answer https://stackoverflow.com/a/28904792/4795651 edited a little for

High memory usage looping through PHAssets and calling requestImageForAsset

删除回忆录丶 提交于 2019-11-27 18:08:38
问题 I'm using an image picker library to allow the user to select many images from their photo library. They are returned as an array of PHAssets . Then, I want to convert all the PHAssets to UIImages and write them to the app's storage. At the moment, I'm looping through all the assets and calling requestImageForAsset synchronously. My issue is that there is incredibly high memory usage spike when this loop is being run (with 30 images, it spikes up to 130MB). I would like to prevent this. Here

Save image to photo library using photo framework

ぃ、小莉子 提交于 2019-11-27 16:12:36
问题 My app crashes every time when I try to save image using photo framework. -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ _mChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[info valueForKey:UIImagePickerControllerOriginalImage]]; [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ _mChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[info valueForKey

iOS8 Photos Framework: How to get the name(or filename) of a PHAsset?

自闭症网瘾萝莉.ら 提交于 2019-11-27 04:14:52
Im trying to get the image name using PHAssets . But I couldn't find metadata for filename or any method to get the image name. Is there a different way to get the file name? If you want to get the image name (for example name of last photo in Photos) like IMG_XXX.JPG, you can try this: PHAsset *asset = nil; PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init]; fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]]; PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions]; if

NSURL from PHAsset

巧了我就是萌 提交于 2019-11-27 03:49:31
I'm converting our app over to use the Photos Framework of iOS8, the ALAsset framework is clearly a second class citizen under iOS8. I'm having a problem is that our architecture really wants an NSURL that represents the location of the media on "disk." We use this to upload the media to our servers for further processing. This was easy with ALAsset: ALAssetRepresentation *rep = [asset defaultRepresentation]; self.originalVideo = rep.url; But I'm just not seeing this ability in PHAsset. I guess I can call: imageManager.requestImageDataForAsset and then write it out to a temp spot in the file

PHAsset to UIImage

馋奶兔 提交于 2019-11-27 00:33:33
问题 I'm attempting to create a UIImage (like a thumbnail or something) from a PHAsset so that I can pass it into something that takes a UIImage. I've tried adapting solutions I found on SO (since they all just directly pass it into say a tableview or something), but I have no success (likely because I'm not doing it right). func getAssetThumbnail(asset: PHAsset) -> UIImage { var retimage = UIImage() println(retimage) let manager = PHImageManager.defaultManager() manager.requestImageForAsset(asset