我有一些从ALAssetsLibrary返回的照片。现在,我想在UIImageView
中显示它。我尝试了以下代码,但是出现了一些错误:
var assets : ALAsset = photoArray.objectAtIndex(indexPath.row) as ALAsset
cell.cameraOutlet.image = UIImage(CGImage: assets.thumbnail()) as UIImage // Showing error - Missing argument for parameter 'inBundle' in call
之后,我尝试了这段代码:
var assets : ALAsset = (photoArray.objectAtIndex(indexPath.row) as ALAsset)
var imageRef : CGImageRef = assets.thumbnail() as CGImageRef // showing error - Unmanaged<CGImage>, is not convertible to CGImageRef
cell.cameraOutlet.image = UIImage(CGImage: assets.thumbnail()) as UIImage // Showing error - Missing argument for parameter 'inBundle' in call
我想展示图片,我该怎么做?
dispatch_async(dispatch_get_main_queue(), {
self.photoLibrary.enumerateGroupsWithTypes(ALAssetsGroupType(ALAssetsGroupAlbum),
usingBlock: {
(group: ALAssetsGroup!, stop: UnsafePointer<ObjCBool>) -> Void in
if group != nil {
group.enumerateAssetsUsingBlock({
(asset: ALAsset!, index: Int, stop: UnsafePointer<ObjCBool>) -> Void in
if asset != nil
{
if asset.valueForProperty(ALAssetPropertyType).isEqualToString(ALAssetTypePhoto)
{
self.photoArray.addObject(asset)
}
}
})
}
self.collectionView.reloadData()
},
failureBlock: {
(myerror: NSError!) -> Void in
println("error occurred: \(myerror.localizedDescription)")
})
})
override func numberOfSectionsInCollectionView(collectionView: UICollectionView!) -> Int {
//#warning Incomplete method implementation -- Return the number of sections
return photoArray.count
}
override func collectionView(collectionView: UICollectionView!, numberOfItemsInSection section: Int) -> Int {
//#warning Incomplete method implementation -- Return the number of items in the section
return 1
}
override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {
let cell : CameraCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Camera", forIndexPath: indexPath) as CameraCollectionViewCell
var asset : ALAsset = photoArray.objectAtIndex(indexPath.row) as ALAsset
cell.cameraOutlet.image = UIImage(CGImage: asset.thumbnail().takeUnretainedValue()) as UIImage
return cell
}
输出只显示了一张图片,我认为是因为代码有问题。
takeRetainedValue()
?谢谢! - ndbroadbent