Diyaa Hamza Diyaa Hamza - 3 months ago 193
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?


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