2015-10-15 66 views
0

到realm.io並指定圖像保存在文件路徑我有需要則相片原因請看到第二視圖控制器預覽捕捉的圖像的視圖控制器。 因此,這裏的問題,我怎麼分配我的形象我的ImageView與alamofireimage? 這是我收到與AlamofireImage

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) 

    }) 

Mock

預覽控制器是不是在模仿。但它捕捉後成爲SEGUE,然後確認後回去的CollectionView控制器

回答

0

AlamofireImage其方法setImageWithURL它是用來從服務器加載ASYN圖像。但野兔你有資產的網址,圖像已經存儲在您的設備,所以Doen't上述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) 
        }) 

    }) 
+0

如果一致性我更喜歡使用AlamofireImage的緣故?因爲在我的收藏視圖控制器我用AlamofireImage將圖像加載到藏品反正 – Happiehappie

+1

你不想使用AlamofireImage的UIImageView的擴展這種特殊情況下。相反,請按照@ Kirit的建議直接使用UIImageView。 AlamofireImage UIImageView擴展旨在與遠程圖像交互,而不是本地圖像。 AlamofireImage的所有其他部分仍然非常有用,但我會避免以這種方式使用UIImageView擴展。 – cnoon

相關問題