Convert between UIImage and Base64 string

后端 未结 24 3117
抹茶落季
抹茶落季 2020-11-22 01:45

Does anyone know how to convert a UIImage to a Base64 string, and then reverse it?

I have the below code; the original image before encoding is good, bu

24条回答
  •  佛祖请我去吃肉
    2020-11-22 02:07

    Swift 3.0

    To convert image to base64 string

    Tested in playground

        var logo = UIImage(named: "image_logo")
        let imageData:Data =  UIImagePNGRepresentation(logo)
        let base64String = imageData.base64EncodedString()
        print(base64String)
    

提交回复
热议问题