I am working with the ALAssetLibrary
to get the images from my camera roll for a custom view I am making. Doing so was pretty simple:
library.enumerateGroupsWithTypes(ALAssetsGroupType(ALAssetsGroupSavedPhotos), usingBlock: {
(group: ALAssetsGroup?, stop: UnsafeMutablePointer<ObjCBool>) in
if group != nil {
group!.setAssetsFilter(ALAssetsFilter.allPhotos())
var indexSet = NSIndexSet(indexesInRange: NSMakeRange(0, group!.numberOfAssets() - 1))
group!.enumerateAssetsAtIndexes(indexSet, options: nil, usingBlock: {
(result: ALAsset!, index: Int, stop: UnsafeMutablePointer<ObjCBool>) in
if (result != nil) {
var alAssetRapresentation: ALAssetRepresentation = result.defaultRepresentation()
var url = alAssetRapresentation.url()
var iRef = alAssetRapresentation.fullResolutionImage().takeUnretainedValue()
var image = UIImage(CGImage: iRef)
}
})
}
}) { (NSError) -> Void in
}
All this works great in the simulator. However on a device, getting the fullResolutionImage()
proves to be way to memory intensive on the device and causes crashes. I figured that makes perfect sense, dozens of high res images all loaded into memory is a terrible idea, so I'd like to scale the quality back and only show the thumbnail of the image. Only issue is that there is no simple way I've found to get a thumbnail from the AlAssetRepresentation
.
I am trying to work with the CGImageSourceCreateThumbnailAtIndex
to create a thumbnail but have been very confused on how to do this.
Any help is much appreciated!