Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thumbnail from filepicker on iOS

When using the built in UIImagePicker from iOS the developer has access to the thumbnail image used in the picker. Is it possible to access the thumbnail used by Filepicker or otherwise access the ALAsset library URL used by Filepicker?

like image 226
Kyle Avatar asked Nov 26 '12 16:11

Kyle


1 Answers

This how I did it, but I must warn you it is slow(ish) and frameworks needed to to this are memory intensive as it iterates over the ALAssetsLibrary looking for posterimages. This on the background thread, so UI changes are sent to the main thread for rendering.

    self.assetsLibrary = [[ALAssetsLibrary alloc] init];

    NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupSavedPhotos | ALAssetsGroupPhotoStream;
    [self.assetsLibrary enumerateGroupsWithTypes:groupTypes
                                  usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                                      if (group.posterImage != nil) {
                                          dispatch_async(dispatch_get_main_queue(), ^{
                                              self.pictureLayer.contents = (__bridge_transfer id) CGImageCreateCopy(group.posterImage);
                                              [self.layer setNeedsDisplay];
                                              self.assetsLibrary = nil;
                                              *stop = YES;
                                          });
                                      }
                                  }
                                failureBlock:^(NSError *error) {
                                    self.assetsLibrary = nil;
                                    NSLog(@"AssetLib error:%@",error);
                                }];
like image 178
Steven Veltema Avatar answered Sep 19 '22 18:09

Steven Veltema