pete pete - 5 days ago 5
Swift Question

Convert UIImage to NSData and convert back to UIImage in Swift?

I'm trying to save a

UIImage
to
NSData
and then read the
NSData
back to a new
UIImage
in Swift. To convert the
UIImage
to
NSData
I'm using the following code:

let imageData: NSData = UIImagePNGRepresentation(myImage)


How do I convert imageData back to a new
UIImage
?

Answer

UIImage(data:imageData,scale:1.0) presuming the image's scale is 1.