Convert Image To Base64 In Swift Ui

[Solved] Convert Image To Base64 In Swift Ui | Swift - Code Explorer | yomemimo.com
Question : convert image to base64 in swift ui

Answered by : depressed-dog-a1fa9gg7f0gn

 func convertImageToBase64(image: UIImage) -> String? { let imageData = image.jpegData(compressionQuality: 1) return imageData?.base64EncodedString(options: Data.Base64EncodingOptions.lineLength64Characters) }

Source : https://stackoverflow.com/questions/59095894/how-to-convert-image-to-base64-in-swiftui | Last Update : Mon, 02 Aug 21

Question : convert image to base64 swift Ui

Answered by : depressed-dog-a1fa9gg7f0gn

//Use image name from bundle to create NSData
let image : UIImage = UIImage(named:"imageNameHere")!
//Now use image to create into NSData format
let imageData:NSData = UIImagePNGRepresentation(image)!
//OR next possibility
//Use image's path to create NSData
let url:NSURL = NSURL(string : "urlHere")!
//Now use image to create into NSData format
let imageData:NSData = NSData.init(contentsOfURL: url)!
let dataDecoded : Data = Data(base64Encoded: strBase64, options: .ignoreUnknownCharacters)!
let decodedimage = UIImage(data: dataDecoded)
yourImageView.image = decodedimage

Source : https://stackoverflow.com/questions/11251340/convert-between-uiimage-and-base64-string | Last Update : Mon, 02 Aug 21

Answers related to convert image to base64 in swift ui

Code Explorer Popular Question For Swift