Convert between UIImage and Base64 string

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

    I tried all the solutions, none worked for me (using Swift 4), this is the solution that worked for me, if anyone in future faces the same problem.

    let temp = base64String.components(separatedBy: ",")
    let dataDecoded : Data = Data(base64Encoded: temp[1], options: 
     .ignoreUnknownCharacters)!
    let decodedimage = UIImage(data: dataDecoded)
    
    yourImage.image = decodedimage
    

提交回复
热议问题