How to detect if video is Landscape/portrait when fetched from PHAsset?

空扰寡人 提交于 2019-12-24 00:56:31

问题


I am fetching videos from PHAsset so user can choose the video and import to perform edit. But user should be only able to select video with Landscape orientation, if user select portrait video, she/he would get alert message saying that its portrait video and hence can not import to edit.

One way to do this is creating AVAsset from URL of PHFetchResults, and then checking a preferedTransform, but that would be very costly operation to do right?

Is there a way to do this without creating AVasset?


回答1:


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
}

Available in iOS 8.0 and later.



来源:https://stackoverflow.com/questions/37596555/how-to-detect-if-video-is-landscape-portrait-when-fetched-from-phasset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!