Last active
January 12, 2024 14:45
-
-
Save trilliwon/5af1abe1a113148c23ecde8c08e181a6 to your computer and use it in GitHub Desktop.
Swift UIImage to Data, Data to UIImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The PNG format includes compression by default