0

How can I get the aspect ratio for the image which comes from the server?

EDIT:If I get many image in the network, how can I get them by using async function ? and in the block to get their aspect ratio?

lme
  • 59
  • 3
  • 17

1 Answers1

1

Once you download the image, create an UIImage instance by using the downloaded data then through size property, you will be able to determine the height and width of the actual image downloaded :

let image = UIImage(data: <imageDownloadeddata>)
let imgWidth = image.size.width
let imgHeight = image.size.height
Chengappa C D
  • 1,841
  • 1
  • 12
  • 19
  • Your answer is very good, but I have edited my question, do you know how to get `image data` in using `asyn-function` and in block to get their `aspect ratio`? If their is `triple sdk` like `SDWbImage` can do that? – lme Jun 28 '16 at 11:28
  • Even if you are downloading the images asynchronously, In the completion block you will have the image data downloaded. All you have to do is place the above code in your completion block, as the only thing you need is the downloaded data, which should be available with you in the completion block. – Chengappa C D Jun 28 '16 at 13:03
  • @Chanadan005 Thanks, I just don't know how to download the images asynchronously.Is there a example? – lme Jun 29 '16 at 01:31
  • Refer this, it should help you : http://stackoverflow.com/questions/24231680/loading-downloading-image-from-url-on-swift – Chengappa C D Jun 29 '16 at 06:59