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

前端 未结 9 1483
一向
一向 2020-12-02 07:33

I\'m trying to save a UIImage to NSData and then read the NSData back to a new UIImage in Swift. To convert the UII

9条回答
  •  粉色の甜心
    2020-12-02 07:55

    Now in Swift 4.2 you can use pngData() new instance method of UIImage to get the data from the image

    let profileImage = UIImage(named:"profile")!
    let imageData = profileImage.pngData()
    

提交回复
热议问题