我有一个视图控制器拍摄照片然后转到第二个视图控制器以预览捕获的图像。 所以这就是问题所在,如何使用alamofireimage将图像分配到我的imageview? 这是我收到的路径
assets-library://asset/asset.JPG?id=16F4079E-38B2-4B7C-953A-22395A528B5D&ext=JPG
任何人都可以建议我如何使用它?
我的代码如下
let imageData = UIImageJPEGRepresentation(self.image!, 0.8)
let compressedImage = UIImage(data: imageData!)
ALAssetsLibrary().writeImageToSavedPhotosAlbum(compressedImage?.CGImage, orientation: ALAssetOrientation(rawValue: compressedImage!.imageOrientation.rawValue)!, completionBlock: {
(path:NSURL!, error:NSError!) -> Void in
print("\(path)")
self.previewImageView.af_setImageWithURL(path)
})
预览控制器不在模拟中。但是在捕捉后它会变为segue,然后在确认后返回到collectionview控制器
答案 0 :(得分:0)
AlamofireImage 其方法setImageWithURL
,用于从服务器asyn加载图像。但是你有资产URL,你的设备中已经存储了哪个图像,所以不要使用AlamofireImage的上述方法。
使用以下代码从ALAsset URL加载图片:
let imageData = UIImageJPEGRepresentation(self.image!, 0.8)
let compressedImage = UIImage(data: imageData!)
ALAssetsLibrary().writeImageToSavedPhotosAlbum(compressedImage?.CGImage, orientation: ALAssetOrientation(rawValue: compressedImage!.imageOrientation.rawValue)!, completionBlock: {
(path:NSURL!, error:NSError!) -> Void in
print("\(path)")
assetLibrary.assetForURL(path, resultBlock: { (asset: ALAsset!) -> Void in
if asset != nil {
var assetRep: ALAssetRepresentation = asset.defaultRepresentation()
var iref = assetRep.fullScreenImage().takeUnretainedValue()
var image = UIImage(CGImage: iref)
self.previewImageView.image = image
}
}, failureBlock: { (error: NSError!) -> Void in
println(error.localizedDescription)
})
})