Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting size (height and width) from PHAsset

Is there a way to get the height and width of the image from a PHAsset object.

I'm trying to make an image picker with a custom UICollectionViewLayout (Kind of like the main page of Pinterest app) I'v fetched all of the photos from the photo library into an array as PHAsset objects. But I need to get the size of the image from the PHAsset object for the delegate method collectionView:layout:sizeForItemAtIndexPath:

Is there a fast way to achieve this?

like image 227
Abbin Varghese Avatar asked Sep 24 '16 08:09

Abbin Varghese


2 Answers

PHAsset has pixelWidth and pixelHeight properties.

like image 52
Francescu Avatar answered Nov 10 '22 23:11

Francescu


You can get them using this.

let imgheight = yourAsset.pixelHeight
let imgwidth = yourAsset.pixelWidth
like image 20
Anna K. Avatar answered Nov 10 '22 23:11

Anna K.