Convert between UIImage and Base64 string

后端 未结 24 2545
抹茶落季
抹茶落季 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:13

    In Swift 3.0

    func decodeBase64(toImage strEncodeData: String) -> UIImage {
    
        let dataDecoded  = NSData(base64Encoded: strEncodeData, options: NSData.Base64DecodingOptions.ignoreUnknownCharacters)!
        let image = UIImage(data: dataDecoded as Data)
        return image!
    
    }
    

提交回复
热议问题