UIImageJPEGRepresentation has been replaced by instance method UIImage.jpegData(compressionQuality:)

自闭症网瘾萝莉.ら 提交于 2019-11-27 07:59:42

The error is telling you that as of iOS 12 the old UIImageJPEGRepresentation function has been replaced with the new jpegData method on UIImage.

Change:

let imageData = UIImageJPEGRepresentation(image, 0.75)

to:

let imageData = image.jpegData(compressionQuality: 0.75)

Similarly, the use of UIImagePNGRepresentation has been replaced with pngData().

Just replace

guard let imageData = UIImageJPEGRepresentation(image, 0.75) else { return }

with:

guard let imageData = image.jpegData(compressionQuality: 0.75) else { return }

This error occurred in ios 12 and swift 4.2 version.

let image = UIImage()
let imageData = UIImageJPEGRepresentation(image, 1)

to:

let image = UIImage()
let imageData = image.jpegData(compressionQuality: 0.50)

you want to change like this. Please try this it's working for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!