简体   繁体   English

如何从保存的照片中获取ALAsset

[英]How to get ALAsset from saved photo

Is there a way to know the ALAsset corresponding to an UIImage? 有没有办法知道对应于UIImage的ALAsset?

I use UIImageWriteToSavedPhotosAlbum for saving a photo and I need to identify it in my asset list 我使用UIImageWriteToSavedPhotosAlbum保存照片,并且需要在资产列表中进行标识

UPDATE : 更新:

I used writeImageToSavedPhotosAlbum instead of UIImageWriteToSavedPhotosAlbum 我使用了writeImageToSavedPhotosAlbum而不是UIImageWriteToSavedPhotosAlbum

alAssetLibrary.writeImageToSavedPhotosAlbum(image.CGImage, orientation: orientation) { (url, error) -> Void in
    alAssetLibrary.assetForURL(url, resultBlock: { (asset) -> Void in
        //code
    }, failureBlock: { (error) -> Void in
        //code
    })
}

I use UIImageWriteToSavedPhotosAlbum for saving a photo and I need to identify it in my asset list 我使用UIImageWriteToSavedPhotosAlbum保存照片,并且需要在资产列表中进行标识

If you need to identify the resulting asset, why are you using UIImageWriteToSavedPhotosAlbum ? 如果需要标识结果资产,那么为什么要使用UIImageWriteToSavedPhotosAlbum It is a "stupid" function. 这是一个“愚蠢”的功能。

If you want to save an image as an asset into the library in such a way that you have access to that asset, you need to save it a "smart" way, such ALAssetsLibrary's writeImageToSavedPhotosAlbum - which has a completion handler that hands you the URL of the resulting asset. 如果您想以可以访问资产的方式将图像作为资产保存到库中,则需要以“智能”方式将其保存,例如ALAssetsLibrary的writeImageToSavedPhotosAlbum具有完成处理程序,可以将URL交给您产生的资产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM