简体   繁体   English

来自NSURL的Swift PHAsset

[英]Swift PHAsset from NSURL

I am working on PHAsset and NSURL on Swift. 我正在Swift上开发PHAsset和NSURL。 I have an image url, for example file:///var/mobile/Media/DCIM/100APPLE/IMG_0043.JPG . 我有一个图片网址,例如file:///var/mobile/Media/DCIM/100APPLE/IMG_0043.JPG

How can i make a PHAsset from this NSURL in Swift? 如何在Swift中从此NSURL制作PHAsset?

A PHAsset object represents an image or video file that appears in the Photos app, including iCloud Photos content. PHAsset对象代表出现在“照片”应用程序中的图像或视频文件,包括iCloud Photos内容。 To display or edit assets, use the PHAsset class to fetch asset objects for the photos or videos you want to work with. 要显示或编辑资产,请使用PHAsset类为要使用的照片或视频获取资产对象。 An asset object is immutable and contains only the metadata for the photo or video it represents. 资产对象是不可变的,并且仅包含其表示的照片或视频的元数据。

Thus you can not make PHAsset object. 因此,您不能使PHAsset对象。 Here is only one constructor for making object. 这里只有一个用于构造对象的构造函数。

let asset   =   PHAsset()

There is no constructor for NSURL :- 没有NSURL的构造函数:

This is what we frequently use:- 这是我们经常使用的:

let imgData = NSData(contentsOfURL: (NSURL(string: "file:///var/mobile/Media/DCIM/100APPLE/IMG_0043.JPG"))!)
let image = UIImage(data: imgData!)

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

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