我正在从 PHAsset 获取视频,以便用户可以选择视频并导入以执行编辑。但用户应该只能选择横向视频,如果用户选择纵向视频,她/他会收到警告消息,指出其为纵向视频,因此无法导入进行编辑。
一种方法是从 PHFetchResults 的 URL 创建 AVAsset,然后检查 PreferredTransform,但这会是非常昂贵的操作,对吧?
有没有办法在不创建AVasset的情况下做到这一点?
最佳答案
https://developer.apple.com/library/ios/documentation/Photos/Reference/PHAsset_Class/
var pixelWidth: Int { get }
var pixelHeight: Int { get }
The width and height, in pixels, of the asset’s image or video data. (read-only)
If the asset’s content has been edited, this property describes the size of the current version of the asset. Availability iOS (8.0 and later)
if asset!.pixelHeight > asset!.pixelWidth {
// will be portrait video or Image
}
适用于 iOS 8.0 及更高版本。
关于ios - 从 PHAsset 获取视频时如何检测视频是否为横向/纵向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37596555/