Reputation: 313
I have a set of Data coming from a request (AlamoFire) as per the image below:
I know it's an image, the size of the data is correct. I'd like to create an image from this and tried:
NSImage(data: result)
or
NSImage.init(data:result)
Without success. It is possible to do what I try to achieve?
EDIT: to answer Larme on Self.coverImage:
Upvotes: 0
Views: 544
Reputation: 1526
This is a iOS snippet, if is useful for anyone:
// Swift
// Image to data
let image = UIImage(named: "sample")
let data = image?.pngData()
let data = image?.jpegData(compressionQuality: 0.9)
// Data to Image
let uiImage: UIImage = UIImage(data: imageData)
// this method is deprecated
var imageData: Data = UIImagePNGRepresentation(image)
Upvotes: -2