Skip to content

Instantly share code, notes, and snippets.

@trilliwon
Last active January 12, 2024 14:45
Show Gist options
  • Save trilliwon/5af1abe1a113148c23ecde8c08e181a6 to your computer and use it in GitHub Desktop.
Save trilliwon/5af1abe1a113148c23ecde8c08e181a6 to your computer and use it in GitHub Desktop.
Swift UIImage to Data, Data to UIImage
// Swift4
let image = UIImage(named: "sample")
let data = image?.pngData()
let data = image?.jpegData(compressionQuality: 0.9)
let uiImage: UIImage = UIImage(data: imageData)
// deprecated
// var imageData: Data = UIImagePNGRepresentation(image)
@mzm008
Copy link

mzm008 commented Dec 5, 2022

how to convert Image to Data ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment