Diyaa Hamza Diyaa Hamza - 1 year ago 977
iOS Question

Convert UIImage to byte array in swift

How can I convert a UIimage into a Byte Array, so I can upload it into my web service?

Answer Source

you can actually even use a single line to do it

let image = UIImage(named: "someImage")
if let unwrappedImage = image {
  let data = UIImageJPEGRepresentation(unwrappedImage, 1.0)

the number should range from 0.0 to 1.0 and sets the jpeg quality

--- update ---

still valid as of Swift 3.0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download